devlyn-cli 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +4 -2
  2. package/bin/devlyn.js +184 -147
  3. package/bin/skill-history.json +140 -0
  4. package/bin/skill-ownership.js +67 -0
  5. package/node_modules/@inquirer/ansi/LICENSE +22 -0
  6. package/node_modules/@inquirer/ansi/README.md +121 -0
  7. package/node_modules/@inquirer/ansi/dist/index.d.ts +14 -0
  8. package/node_modules/@inquirer/ansi/dist/index.js +21 -0
  9. package/node_modules/@inquirer/ansi/package.json +79 -0
  10. package/node_modules/@inquirer/checkbox/LICENSE +22 -0
  11. package/node_modules/@inquirer/checkbox/README.md +265 -0
  12. package/node_modules/@inquirer/checkbox/dist/index.d.ts +67 -0
  13. package/node_modules/@inquirer/checkbox/dist/index.js +210 -0
  14. package/node_modules/@inquirer/checkbox/package.json +93 -0
  15. package/node_modules/@inquirer/core/LICENSE +22 -0
  16. package/node_modules/@inquirer/core/README.md +424 -0
  17. package/node_modules/@inquirer/core/dist/index.d.ts +13 -0
  18. package/node_modules/@inquirer/core/dist/index.js +12 -0
  19. package/node_modules/@inquirer/core/dist/lib/Separator.d.ts +10 -0
  20. package/node_modules/@inquirer/core/dist/lib/Separator.js +21 -0
  21. package/node_modules/@inquirer/core/dist/lib/__probe/p1.d.ts +9 -0
  22. package/node_modules/@inquirer/core/dist/lib/__probe/p1.js +4 -0
  23. package/node_modules/@inquirer/core/dist/lib/__probe/p2.d.ts +9 -0
  24. package/node_modules/@inquirer/core/dist/lib/__probe/p2.js +3 -0
  25. package/node_modules/@inquirer/core/dist/lib/__probe/p3.d.ts +9 -0
  26. package/node_modules/@inquirer/core/dist/lib/__probe/p3.js +5 -0
  27. package/node_modules/@inquirer/core/dist/lib/create-prompt.d.ts +11 -0
  28. package/node_modules/@inquirer/core/dist/lib/create-prompt.js +185 -0
  29. package/node_modules/@inquirer/core/dist/lib/errors.d.ts +20 -0
  30. package/node_modules/@inquirer/core/dist/lib/errors.js +21 -0
  31. package/node_modules/@inquirer/core/dist/lib/hook-engine.d.ts +17 -0
  32. package/node_modules/@inquirer/core/dist/lib/hook-engine.js +109 -0
  33. package/node_modules/@inquirer/core/dist/lib/key.d.ts +15 -0
  34. package/node_modules/@inquirer/core/dist/lib/key.js +34 -0
  35. package/node_modules/@inquirer/core/dist/lib/make-theme.d.ts +3 -0
  36. package/node_modules/@inquirer/core/dist/lib/make-theme.js +33 -0
  37. package/node_modules/@inquirer/core/dist/lib/pagination/use-pagination.d.ts +15 -0
  38. package/node_modules/@inquirer/core/dist/lib/pagination/use-pagination.js +121 -0
  39. package/node_modules/@inquirer/core/dist/lib/screen-manager.d.ts +14 -0
  40. package/node_modules/@inquirer/core/dist/lib/screen-manager.js +84 -0
  41. package/node_modules/@inquirer/core/dist/lib/theme.d.ts +166 -0
  42. package/node_modules/@inquirer/core/dist/lib/theme.js +29 -0
  43. package/node_modules/@inquirer/core/dist/lib/use-effect.d.ts +2 -0
  44. package/node_modules/@inquirer/core/dist/lib/use-effect.js +11 -0
  45. package/node_modules/@inquirer/core/dist/lib/use-keypress.d.ts +3 -0
  46. package/node_modules/@inquirer/core/dist/lib/use-keypress.js +20 -0
  47. package/node_modules/@inquirer/core/dist/lib/use-memo.d.ts +1 -0
  48. package/node_modules/@inquirer/core/dist/lib/use-memo.js +14 -0
  49. package/node_modules/@inquirer/core/dist/lib/use-prefix.d.ts +5 -0
  50. package/node_modules/@inquirer/core/dist/lib/use-prefix.js +35 -0
  51. package/node_modules/@inquirer/core/dist/lib/use-ref.d.ts +6 -0
  52. package/node_modules/@inquirer/core/dist/lib/use-ref.js +4 -0
  53. package/node_modules/@inquirer/core/dist/lib/use-state.d.ts +7 -0
  54. package/node_modules/@inquirer/core/dist/lib/use-state.js +28 -0
  55. package/node_modules/@inquirer/core/dist/lib/utils.d.ts +13 -0
  56. package/node_modules/@inquirer/core/dist/lib/utils.js +25 -0
  57. package/node_modules/@inquirer/core/package.json +98 -0
  58. package/node_modules/@inquirer/figures/LICENSE +22 -0
  59. package/node_modules/@inquirer/figures/dist/index.d.ts +275 -0
  60. package/node_modules/@inquirer/figures/dist/index.js +315 -0
  61. package/node_modules/@inquirer/figures/package.json +81 -0
  62. package/node_modules/@inquirer/select/LICENSE +22 -0
  63. package/node_modules/@inquirer/select/README.md +258 -0
  64. package/node_modules/@inquirer/select/dist/index.d.ts +42 -0
  65. package/node_modules/@inquirer/select/dist/index.js +191 -0
  66. package/node_modules/@inquirer/select/package.json +93 -0
  67. package/node_modules/@inquirer/type/LICENSE +22 -0
  68. package/node_modules/@inquirer/type/dist/index.d.ts +2 -0
  69. package/node_modules/@inquirer/type/dist/index.js +2 -0
  70. package/node_modules/@inquirer/type/dist/inquirer.d.ts +35 -0
  71. package/node_modules/@inquirer/type/dist/inquirer.js +1 -0
  72. package/node_modules/@inquirer/type/dist/utils.d.ts +45 -0
  73. package/node_modules/@inquirer/type/dist/utils.js +16 -0
  74. package/node_modules/@inquirer/type/package.json +88 -0
  75. package/node_modules/cli-width/LICENSE +13 -0
  76. package/node_modules/cli-width/README.md +71 -0
  77. package/node_modules/cli-width/index.d.ts +13 -0
  78. package/node_modules/cli-width/index.js +49 -0
  79. package/node_modules/cli-width/package.json +40 -0
  80. package/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
  81. package/node_modules/fast-string-truncated-width/dist/index.js +111 -0
  82. package/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
  83. package/node_modules/fast-string-truncated-width/dist/types.js +2 -0
  84. package/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
  85. package/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
  86. package/node_modules/fast-string-truncated-width/license +21 -0
  87. package/node_modules/fast-string-truncated-width/package.json +35 -0
  88. package/node_modules/fast-string-truncated-width/readme.md +59 -0
  89. package/node_modules/fast-string-width/dist/index.d.ts +4 -0
  90. package/node_modules/fast-string-width/dist/index.js +14 -0
  91. package/node_modules/fast-string-width/license +21 -0
  92. package/node_modules/fast-string-width/package.json +34 -0
  93. package/node_modules/fast-string-width/readme.md +42 -0
  94. package/node_modules/fast-wrap-ansi/LICENSE +23 -0
  95. package/node_modules/fast-wrap-ansi/README.md +26 -0
  96. package/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
  97. package/node_modules/fast-wrap-ansi/lib/main.js +218 -0
  98. package/node_modules/fast-wrap-ansi/package.json +51 -0
  99. package/node_modules/mute-stream/LICENSE +15 -0
  100. package/node_modules/mute-stream/README.md +68 -0
  101. package/node_modules/mute-stream/lib/index.js +142 -0
  102. package/node_modules/mute-stream/package.json +54 -0
  103. package/node_modules/signal-exit/LICENSE.txt +16 -0
  104. package/node_modules/signal-exit/README.md +74 -0
  105. package/node_modules/signal-exit/dist/cjs/browser.d.ts +12 -0
  106. package/node_modules/signal-exit/dist/cjs/browser.d.ts.map +1 -0
  107. package/node_modules/signal-exit/dist/cjs/browser.js +10 -0
  108. package/node_modules/signal-exit/dist/cjs/browser.js.map +1 -0
  109. package/node_modules/signal-exit/dist/cjs/index.d.ts +48 -0
  110. package/node_modules/signal-exit/dist/cjs/index.d.ts.map +1 -0
  111. package/node_modules/signal-exit/dist/cjs/index.js +279 -0
  112. package/node_modules/signal-exit/dist/cjs/index.js.map +1 -0
  113. package/node_modules/signal-exit/dist/cjs/package.json +3 -0
  114. package/node_modules/signal-exit/dist/cjs/signals.d.ts +29 -0
  115. package/node_modules/signal-exit/dist/cjs/signals.d.ts.map +1 -0
  116. package/node_modules/signal-exit/dist/cjs/signals.js +42 -0
  117. package/node_modules/signal-exit/dist/cjs/signals.js.map +1 -0
  118. package/node_modules/signal-exit/dist/mjs/browser.d.ts +12 -0
  119. package/node_modules/signal-exit/dist/mjs/browser.d.ts.map +1 -0
  120. package/node_modules/signal-exit/dist/mjs/browser.js +4 -0
  121. package/node_modules/signal-exit/dist/mjs/browser.js.map +1 -0
  122. package/node_modules/signal-exit/dist/mjs/index.d.ts +48 -0
  123. package/node_modules/signal-exit/dist/mjs/index.d.ts.map +1 -0
  124. package/node_modules/signal-exit/dist/mjs/index.js +275 -0
  125. package/node_modules/signal-exit/dist/mjs/index.js.map +1 -0
  126. package/node_modules/signal-exit/dist/mjs/package.json +3 -0
  127. package/node_modules/signal-exit/dist/mjs/signals.d.ts +29 -0
  128. package/node_modules/signal-exit/dist/mjs/signals.d.ts.map +1 -0
  129. package/node_modules/signal-exit/dist/mjs/signals.js +39 -0
  130. package/node_modules/signal-exit/dist/mjs/signals.js.map +1 -0
  131. package/node_modules/signal-exit/package.json +106 -0
  132. package/package.json +16 -2
@@ -0,0 +1,45 @@
1
+ type Key = string | number | symbol;
2
+ /**
3
+ * Recursively expand intersections and mapped types for better IDE display,
4
+ * while preserving functions, arrays, primitives, and types with a string
5
+ * index signature (e.g. `Record<string, ...>`) as-is.
6
+ */
7
+ export type Prettify<T> = T extends (...args: never[]) => unknown ? T : T extends ReadonlyArray<unknown> ? T : T extends string | number | boolean | symbol | bigint | null | undefined ? T : T extends object ? string extends keyof T ? T : {
8
+ [K in keyof T]: Prettify<T[K]>;
9
+ } & {} : T;
10
+ export type PartialDeep<T> = T extends object ? {
11
+ [P in keyof T]?: PartialDeep<T[P]>;
12
+ } : T;
13
+ export type LiteralUnion<T extends F, F = string> = T | (F & {});
14
+ export type KeyUnion<T> = LiteralUnion<Extract<keyof T, string>>;
15
+ export type DistributiveMerge<A, B> = A extends any ? Prettify<Omit<A, keyof B> & B> : never;
16
+ export type UnionToIntersection<T> = (T extends any ? (input: T) => void : never) extends (input: infer Intersection) => void ? Intersection : never;
17
+ /**
18
+ * @hidden
19
+ */
20
+ type __Pick<O extends object, K extends keyof O> = {
21
+ [P in K]: O[P];
22
+ } & {};
23
+ /**
24
+ * @hidden
25
+ */
26
+ export type _Pick<O extends object, K extends Key> = __Pick<O, keyof O & K>;
27
+ /**
28
+ * Extract out of `O` the fields of key `K`
29
+ * @param O to extract from
30
+ * @param K to chose fields
31
+ * @returns [[Object]]
32
+ */
33
+ export type Pick<O extends object, K extends Key> = O extends unknown ? _Pick<O, K> : never;
34
+ /**
35
+ * Create a promise and get access to its `resolve` and `reject` functions.
36
+ *
37
+ * Mirrors `Promise.withResolvers()`, available starting from Node 22.
38
+ * TODO: Remove once Node 22 becomes the minimum supported version.
39
+ */
40
+ export declare function withResolver<T>(): {
41
+ promise: Promise<T>;
42
+ resolve: (value: T) => void;
43
+ reject: (error: unknown) => void;
44
+ };
45
+ export {};
@@ -0,0 +1,16 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * Create a promise and get access to its `resolve` and `reject` functions.
4
+ *
5
+ * Mirrors `Promise.withResolvers()`, available starting from Node 22.
6
+ * TODO: Remove once Node 22 becomes the minimum supported version.
7
+ */
8
+ export function withResolver() {
9
+ let resolve;
10
+ let reject;
11
+ const promise = new Promise((res, rej) => {
12
+ resolve = res;
13
+ reject = rej;
14
+ });
15
+ return { promise, resolve: resolve, reject: reject };
16
+ }
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@inquirer/type",
3
+ "version": "4.2.0",
4
+ "description": "Inquirer core TS types",
5
+ "keywords": [
6
+ "answer",
7
+ "answers",
8
+ "ask",
9
+ "base",
10
+ "cli",
11
+ "command",
12
+ "command-line",
13
+ "confirm",
14
+ "enquirer",
15
+ "generate",
16
+ "generator",
17
+ "hyper",
18
+ "input",
19
+ "inquire",
20
+ "inquirer",
21
+ "interface",
22
+ "iterm",
23
+ "javascript",
24
+ "menu",
25
+ "node",
26
+ "nodejs",
27
+ "prompt",
28
+ "promptly",
29
+ "prompts",
30
+ "question",
31
+ "readline",
32
+ "scaffold",
33
+ "scaffolder",
34
+ "scaffolding",
35
+ "stdin",
36
+ "stdout",
37
+ "terminal",
38
+ "tty",
39
+ "types",
40
+ "typescript",
41
+ "ui",
42
+ "yeoman",
43
+ "yo",
44
+ "zsh"
45
+ ],
46
+ "license": "MIT",
47
+ "author": "Simon Boudrias <admin@simonboudrias.com>",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/SBoudrias/Inquirer.js.git"
51
+ },
52
+ "files": [
53
+ "dist"
54
+ ],
55
+ "type": "module",
56
+ "sideEffects": false,
57
+ "exports": {
58
+ ".": {
59
+ "types": "./dist/index.d.ts",
60
+ "default": "./dist/index.js"
61
+ },
62
+ "./package.json": "./package.json"
63
+ },
64
+ "publishConfig": {
65
+ "access": "public"
66
+ },
67
+ "scripts": {
68
+ "tsc": "tsc"
69
+ },
70
+ "devDependencies": {
71
+ "@repo/tsconfig": "0.0.0",
72
+ "typescript": "^6.0.2"
73
+ },
74
+ "peerDependencies": {
75
+ "@types/node": ">=18"
76
+ },
77
+ "peerDependenciesMeta": {
78
+ "@types/node": {
79
+ "optional": true
80
+ }
81
+ },
82
+ "engines": {
83
+ "node": ">=23.5.0 || ^22.13.0 || ^20.17.0"
84
+ },
85
+ "main": "./dist/index.js",
86
+ "types": "./dist/index.d.ts",
87
+ "gitHead": "a9436bd94d55a439df308f50e77a7cd0b2078e98"
88
+ }
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2015, Ilya Radchenko <knownasilya@gmail.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # cli-width
2
+
3
+ Get stdout window width, with four fallbacks, `tty`, `output.columns`, a custom environment variable and then a default.
4
+
5
+ [![npm version](https://badge.fury.io/js/cli-width.svg)](http://badge.fury.io/js/cli-width)
6
+ [![Build Status](https://travis-ci.org/knownasilya/cli-width.svg)](https://travis-ci.org/knownasilya/cli-width)
7
+ [![Coverage Status](https://coveralls.io/repos/knownasilya/cli-width/badge.svg?branch=master&service=github)](https://coveralls.io/github/knownasilya/cli-width?branch=master)
8
+
9
+ Tested against Node v12 to v20.
10
+ Includes TypeScript types.
11
+
12
+ ## Usage
13
+
14
+ ```
15
+ npm install --save cli-width
16
+ ```
17
+
18
+ ```js
19
+ const cliWidth = require('cli-width');
20
+
21
+ cliWidth(); // maybe 204 :)
22
+ ```
23
+
24
+ You can also set the `CLI_WIDTH` environment variable.
25
+
26
+ If none of the methods are supported, and the environment variable isn't set,
27
+ the default width value is going to be `0`, that can be changed using the configurable `options`.
28
+
29
+ ## API
30
+
31
+ ### cliWidth([options])
32
+
33
+ `cliWidth` can be configured using an `options` parameter, the possible properties are:
34
+
35
+ - **defaultWidth**\<number\> Defines a default value to be used if none of the methods are available, defaults to `0`
36
+ - **output**\<object\> A stream to be used to read width values from, defaults to `process.stdout`
37
+ - **tty**\<object\> TTY module to try to read width from as a fallback, defaults to `require('tty')`
38
+
39
+ ### Examples
40
+
41
+ Defining both a default width value and a stream output to try to read from:
42
+
43
+ ```js
44
+ const cliWidth = require('cli-width');
45
+ const ttys = require('ttys');
46
+
47
+ cliWidth({
48
+ defaultWidth: 80,
49
+ output: ttys.output,
50
+ });
51
+ ```
52
+
53
+ Defines a different tty module to read width from:
54
+
55
+ ```js
56
+ const cliWidth = require('cli-width');
57
+ const ttys = require('ttys');
58
+
59
+ cliWidth({
60
+ tty: ttys,
61
+ });
62
+ ```
63
+
64
+ ## Tests
65
+
66
+ ```bash
67
+ npm install
68
+ npm test
69
+ ```
70
+
71
+ Coverage can be generated with `npm run coverage`.
@@ -0,0 +1,13 @@
1
+ // Type definitions for cli-width 4.0
2
+ /// <reference types="node" />
3
+
4
+ import { Stream } from 'stream';
5
+ import tty = require('tty');
6
+
7
+ declare function cliWidth(options?: {
8
+ defaultWidth?: number;
9
+ output?: Stream;
10
+ tty?: typeof tty;
11
+ }): number;
12
+
13
+ export = cliWidth;
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ module.exports = cliWidth;
4
+
5
+ function normalizeOpts(options) {
6
+ const defaultOpts = {
7
+ defaultWidth: 0,
8
+ output: process.stdout,
9
+ tty: require('tty'),
10
+ };
11
+
12
+ if (!options) {
13
+ return defaultOpts;
14
+ }
15
+
16
+ Object.keys(defaultOpts).forEach(function (key) {
17
+ if (!options[key]) {
18
+ options[key] = defaultOpts[key];
19
+ }
20
+ });
21
+
22
+ return options;
23
+ }
24
+
25
+ function cliWidth(options) {
26
+ const opts = normalizeOpts(options);
27
+
28
+ if (opts.output.getWindowSize) {
29
+ return opts.output.getWindowSize()[0] || opts.defaultWidth;
30
+ }
31
+
32
+ if (opts.tty.getWindowSize) {
33
+ return opts.tty.getWindowSize()[1] || opts.defaultWidth;
34
+ }
35
+
36
+ if (opts.output.columns) {
37
+ return opts.output.columns;
38
+ }
39
+
40
+ if (process.env.CLI_WIDTH) {
41
+ const width = parseInt(process.env.CLI_WIDTH, 10);
42
+
43
+ if (!isNaN(width) && width !== 0) {
44
+ return width;
45
+ }
46
+ }
47
+
48
+ return opts.defaultWidth;
49
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "cli-width",
3
+ "version": "4.1.0",
4
+ "description": "Get stdout window width, with two fallbacks, tty and then a default.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "node test | tspec",
8
+ "coverage": "nyc node test | tspec",
9
+ "coveralls": "npm run coverage -s && coveralls < coverage/lcov.info",
10
+ "release": "standard-version"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git@github.com:knownasilya/cli-width.git"
15
+ },
16
+ "author": "Ilya Radchenko <knownasilya@gmail.com>",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://github.com/knownasilya/cli-width/issues"
20
+ },
21
+ "homepage": "https://github.com/knownasilya/cli-width",
22
+ "engines": {
23
+ "node": ">= 12"
24
+ },
25
+ "devDependencies": {
26
+ "coveralls": "^3.1.1",
27
+ "nyc": "^15.1.0",
28
+ "standard-version": "^9.3.2",
29
+ "tap-spec": "^5.0.0",
30
+ "tape": "^5.5.2"
31
+ },
32
+ "volta": {
33
+ "node": "12.22.11",
34
+ "npm": "8.5.5"
35
+ },
36
+ "files": [
37
+ "index.js",
38
+ "index.d.ts"
39
+ ]
40
+ }
@@ -0,0 +1,4 @@
1
+ import type { TruncationOptions, WidthOptions, Result } from './types.js';
2
+ declare const getStringTruncatedWidth: (input: string, truncationOptions?: TruncationOptions, widthOptions?: WidthOptions) => Result;
3
+ export default getStringTruncatedWidth;
4
+ export type { TruncationOptions, WidthOptions, Result };
@@ -0,0 +1,111 @@
1
+ /* IMPORT */
2
+ import { getCodePointsLength, isFullWidth, isWideNotCJKTNotEmoji } from './utils.js';
3
+ /* HELPERS */
4
+ const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
5
+ const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
6
+ const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu;
7
+ const TAB_RE = /\t{1,1000}/y;
8
+ const EMOJI_RE = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
9
+ const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
10
+ const MODIFIER_RE = /\p{M}+/gu;
11
+ const NO_TRUNCATION = { limit: Infinity, ellipsis: '' };
12
+ /* MAIN */
13
+ const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
14
+ /* CONSTANTS */
15
+ const LIMIT = truncationOptions.limit ?? Infinity;
16
+ const ELLIPSIS = truncationOptions.ellipsis ?? '';
17
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION, widthOptions).width : 0);
18
+ const ANSI_WIDTH = 0;
19
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
20
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
21
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
22
+ const FULL_WIDTH_WIDTH = 2;
23
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
24
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
25
+ const PARSE_BLOCKS = [
26
+ [LATIN_RE, REGULAR_WIDTH],
27
+ [ANSI_RE, ANSI_WIDTH],
28
+ [CONTROL_RE, CONTROL_WIDTH],
29
+ [TAB_RE, TAB_WIDTH],
30
+ [EMOJI_RE, EMOJI_WIDTH],
31
+ [CJKT_WIDE_RE, WIDE_WIDTH],
32
+ ];
33
+ /* STATE */
34
+ let indexPrev = 0;
35
+ let index = 0;
36
+ let length = input.length;
37
+ let lengthExtra = 0;
38
+ let truncationEnabled = false;
39
+ let truncationIndex = length;
40
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
41
+ let unmatchedStart = 0;
42
+ let unmatchedEnd = 0;
43
+ let width = 0;
44
+ let widthExtra = 0;
45
+ /* PARSE LOOP */
46
+ outer: while (true) {
47
+ /* UNMATCHED */
48
+ if ((unmatchedEnd > unmatchedStart) || (index >= length && index > indexPrev)) {
49
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
50
+ lengthExtra = 0;
51
+ for (const char of unmatched.replaceAll(MODIFIER_RE, '')) {
52
+ const codePoint = char.codePointAt(0) || 0;
53
+ if (isFullWidth(codePoint)) {
54
+ widthExtra = FULL_WIDTH_WIDTH;
55
+ }
56
+ else if (isWideNotCJKTNotEmoji(codePoint)) {
57
+ widthExtra = WIDE_WIDTH;
58
+ }
59
+ else {
60
+ widthExtra = REGULAR_WIDTH;
61
+ }
62
+ if ((width + widthExtra) > truncationLimit) {
63
+ truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
64
+ }
65
+ if ((width + widthExtra) > LIMIT) {
66
+ truncationEnabled = true;
67
+ break outer;
68
+ }
69
+ lengthExtra += char.length;
70
+ width += widthExtra;
71
+ }
72
+ unmatchedStart = unmatchedEnd = 0;
73
+ }
74
+ /* EXITING */
75
+ if (index >= length) {
76
+ break outer;
77
+ }
78
+ /* PARSE BLOCKS */
79
+ for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
80
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
81
+ BLOCK_RE.lastIndex = index;
82
+ if (BLOCK_RE.test(input)) {
83
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
84
+ widthExtra = lengthExtra * BLOCK_WIDTH;
85
+ if ((width + widthExtra) > truncationLimit) {
86
+ truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
87
+ }
88
+ if ((width + widthExtra) > LIMIT) {
89
+ truncationEnabled = true;
90
+ break outer;
91
+ }
92
+ width += widthExtra;
93
+ unmatchedStart = indexPrev;
94
+ unmatchedEnd = index;
95
+ index = indexPrev = BLOCK_RE.lastIndex;
96
+ continue outer;
97
+ }
98
+ }
99
+ /* UNMATCHED INDEX */
100
+ index += 1;
101
+ }
102
+ /* RETURN */
103
+ return {
104
+ width: truncationEnabled ? truncationLimit : width,
105
+ index: truncationEnabled ? truncationIndex : length,
106
+ truncated: truncationEnabled,
107
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
108
+ };
109
+ };
110
+ /* EXPORT */
111
+ export default getStringTruncatedWidth;
@@ -0,0 +1,19 @@
1
+ type TruncationOptions = {
2
+ limit?: number;
3
+ ellipsis?: string;
4
+ ellipsisWidth?: number;
5
+ };
6
+ type WidthOptions = {
7
+ controlWidth?: number;
8
+ tabWidth?: number;
9
+ emojiWidth?: number;
10
+ regularWidth?: number;
11
+ wideWidth?: number;
12
+ };
13
+ type Result = {
14
+ width: number;
15
+ index: number;
16
+ truncated: boolean;
17
+ ellipsed: boolean;
18
+ };
19
+ export type { TruncationOptions, WidthOptions, Result };
@@ -0,0 +1,2 @@
1
+ /* MAIN */
2
+ export {};
@@ -0,0 +1,4 @@
1
+ declare const getCodePointsLength: (input: string) => number;
2
+ declare const isFullWidth: (x: number) => boolean;
3
+ declare const isWideNotCJKTNotEmoji: (x: number) => boolean;
4
+ export { getCodePointsLength, isFullWidth, isWideNotCJKTNotEmoji };
@@ -0,0 +1,20 @@
1
+ /* MAIN */
2
+ const getCodePointsLength = (() => {
3
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
4
+ return (input) => {
5
+ let surrogatePairsNr = 0;
6
+ SURROGATE_PAIR_RE.lastIndex = 0;
7
+ while (SURROGATE_PAIR_RE.test(input)) {
8
+ surrogatePairsNr += 1;
9
+ }
10
+ return input.length - surrogatePairsNr;
11
+ };
12
+ })();
13
+ const isFullWidth = (x) => {
14
+ return x === 0x3000 || x >= 0xFF01 && x <= 0xFF60 || x >= 0xFFE0 && x <= 0xFFE6;
15
+ };
16
+ const isWideNotCJKTNotEmoji = (x) => {
17
+ return x === 0x231B || x === 0x2329 || x >= 0x2FF0 && x <= 0x2FFF || x >= 0x3001 && x <= 0x303E || x >= 0x3099 && x <= 0x30FF || x >= 0x3105 && x <= 0x312F || x >= 0x3131 && x <= 0x318E || x >= 0x3190 && x <= 0x31E3 || x >= 0x31EF && x <= 0x321E || x >= 0x3220 && x <= 0x3247 || x >= 0x3250 && x <= 0x4DBF || x >= 0xFE10 && x <= 0xFE19 || x >= 0xFE30 && x <= 0xFE52 || x >= 0xFE54 && x <= 0xFE66 || x >= 0xFE68 && x <= 0xFE6B || x >= 0x1F200 && x <= 0x1F202 || x >= 0x1F210 && x <= 0x1F23B || x >= 0x1F240 && x <= 0x1F248 || x >= 0x20000 && x <= 0x2FFFD || x >= 0x30000 && x <= 0x3FFFD;
18
+ };
19
+ /* EXPORT */
20
+ export { getCodePointsLength, isFullWidth, isWideNotCJKTNotEmoji };
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024-present Fabio Spampinato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "fast-string-truncated-width",
3
+ "repository": "github:fabiospampinato/fast-string-truncated-width",
4
+ "description": "A fast function for calculating where a string should be truncated, given an optional width limit and an ellipsis string.",
5
+ "license": "MIT",
6
+ "version": "3.0.3",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "exports": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "scripts": {
12
+ "benchmark": "tsex benchmark",
13
+ "benchmark:watch": "tsex benchmark --watch",
14
+ "clean": "tsex clean",
15
+ "compile": "tsex compile",
16
+ "compile:watch": "tsex compile --watch",
17
+ "test": "tsex test",
18
+ "test:watch": "tsex test --watch",
19
+ "prepublishOnly": "tsex prepare"
20
+ },
21
+ "keywords": [
22
+ "fast",
23
+ "string",
24
+ "truncated",
25
+ "width",
26
+ "cli",
27
+ "terminal"
28
+ ],
29
+ "devDependencies": {
30
+ "benchloop": "^2.1.1",
31
+ "fava": "^0.3.4",
32
+ "tsex": "^4.0.2",
33
+ "typescript": "^5.7.3"
34
+ }
35
+ }
@@ -0,0 +1,59 @@
1
+ # Fast String Truncated Width
2
+
3
+ A fast function for calculating where a string should be truncated, given a width limit and an ellipsis string.
4
+
5
+ This is a low-level function that basically calculates the visual width of a string and the index at which it should be truncated once printed to the terminal, but taking into account an optional width limit and an optional ellipsis string, so that the string doesn't have to be processed multiple times to be truncated, and how long the part after the truncation point is doesn't cost us anything because we can just ignore it.
6
+
7
+ Note that codepoints considered "ambiguous" in Unicode will always use "regularWidth" as their width, if you need to customize this you should use [`string-width`](https://www.npmjs.com/package/string-width) instead.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install fast-string-truncated-width
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import fastStringTruncatedWidth from 'fast-string-truncated-width';
19
+
20
+ // The width of various classes of characters is configurable
21
+
22
+ const widthOptions = {
23
+ controlWidth: 0,
24
+ tabWidth: 8,
25
+ emojiWidth: 2,
26
+ regularWidth: 1,
27
+ wideWidth: 2
28
+ };
29
+
30
+ // Retrieving the result for a string that fits within our width limit
31
+
32
+ const result1 = fastStringTruncatedWidth ( '\x1b[31mhello', { limit: Infinity, ellipsis: '…' }, widthOptions );
33
+
34
+ result1.truncated; // => false, the string fits within the width limit, it doesn't have to be truncated
35
+ result1.ellipsed; // => false, the ellipsis string doesn't need to be appended to the string
36
+ result1.width; // => 5, the visual width of the string once printed to the terminal
37
+ result1.index; // => 10, the end index at which the string should be sliced, equal to input.length in this case
38
+
39
+ // Retrieving the result for a string that doesn't fit within our width limit
40
+
41
+ const result2 = fastStringTruncatedWidth ( '\x1b[31mhello', { limit: 3, ellipsis: '…' }, widthOptions );
42
+
43
+ result2.truncated; // => true, the string doesn't fit within the width limit, it has to be truncated
44
+ result2.ellipsed; // => true, the ellipsis string should be appended to the string (this isn't always the case, for example if our limit is 0)
45
+ result2.width; // => 2, the visual width of the string once printed to the terminal (this doesn't account for the width of the ellipsis string itself)
46
+ result2.index; // => 7, the end index at which the string should be sliced to truncate it correctly
47
+
48
+ // Let's actually truncate a string
49
+ // If you are truncating a string that may contain ANSI escapes you'll probaly want to put a "reset" escape after the sliced portion of the input
50
+
51
+ const input = '\x1b[31mhello';
52
+ const options = { limit: 3, ellipsis: '…' };
53
+ const result3 = fastStringTruncatedWidth ( input, options, widthOptions );
54
+ const output = `${input.slice ( 0, result3.index )}${result3.ellipsed ? options.ellipsis : ''}`; // => '\x1b[31mhe…'
55
+ ```
56
+
57
+ ## License
58
+
59
+ MIT © Fabio Spampinato
@@ -0,0 +1,4 @@
1
+ import type { WidthOptions as Options } from 'fast-string-truncated-width';
2
+ declare const fastStringWidth: (input: string, options?: Options) => number;
3
+ export default fastStringWidth;
4
+ export type { Options };
@@ -0,0 +1,14 @@
1
+ /* IMPORT */
2
+ import fastStringTruncatedWidth from 'fast-string-truncated-width';
3
+ /* HELPERS */
4
+ const NO_TRUNCATION = {
5
+ limit: Infinity,
6
+ ellipsis: '',
7
+ ellipsisWidth: 0,
8
+ };
9
+ /* MAIN */
10
+ const fastStringWidth = (input, options = {}) => {
11
+ return fastStringTruncatedWidth(input, NO_TRUNCATION, options).width;
12
+ };
13
+ /* EXPORT */
14
+ export default fastStringWidth;
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024-present Fabio Spampinato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.