@chainlink/external-adapter-framework 2.13.0 β 2.13.1
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.
- package/README.md +1 -1
- package/generator-adapter/node_modules/.yarn-integrity +29 -33
- package/generator-adapter/node_modules/@inquirer/ansi/package.json +28 -26
- package/generator-adapter/node_modules/@inquirer/checkbox/dist/index.d.ts +6 -1
- package/generator-adapter/node_modules/@inquirer/checkbox/dist/index.js +30 -10
- package/generator-adapter/node_modules/@inquirer/checkbox/package.json +23 -21
- package/generator-adapter/node_modules/@inquirer/confirm/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/core/dist/index.d.ts +1 -1
- package/generator-adapter/node_modules/@inquirer/core/dist/index.js +1 -1
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/create-prompt.js +51 -25
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/key.d.ts +2 -0
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/key.js +1 -0
- package/generator-adapter/node_modules/@inquirer/core/dist/lib/utils.js +1 -1
- package/generator-adapter/node_modules/@inquirer/core/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/editor/dist/index.d.ts +3 -0
- package/generator-adapter/node_modules/@inquirer/editor/dist/index.js +5 -5
- package/generator-adapter/node_modules/@inquirer/editor/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/expand/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/external-editor/package.json +33 -31
- package/generator-adapter/node_modules/@inquirer/figures/package.json +18 -16
- package/generator-adapter/node_modules/@inquirer/input/dist/index.js +5 -3
- package/generator-adapter/node_modules/@inquirer/input/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/number/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/password/dist/index.d.ts +6 -1
- package/generator-adapter/node_modules/@inquirer/password/dist/index.js +7 -2
- package/generator-adapter/node_modules/@inquirer/password/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/prompts/README.md +15 -0
- package/generator-adapter/node_modules/@inquirer/prompts/package.json +31 -29
- package/generator-adapter/node_modules/@inquirer/rawlist/README.md +4 -0
- package/generator-adapter/node_modules/@inquirer/rawlist/dist/index.d.ts +9 -2
- package/generator-adapter/node_modules/@inquirer/rawlist/dist/index.js +24 -7
- package/generator-adapter/node_modules/@inquirer/rawlist/package.json +21 -19
- package/generator-adapter/node_modules/@inquirer/search/README.md +2 -1
- package/generator-adapter/node_modules/@inquirer/search/dist/index.d.ts +1 -0
- package/generator-adapter/node_modules/@inquirer/search/dist/index.js +11 -4
- package/generator-adapter/node_modules/@inquirer/search/package.json +22 -20
- package/generator-adapter/node_modules/@inquirer/select/dist/index.d.ts +5 -2
- package/generator-adapter/node_modules/@inquirer/select/dist/index.js +28 -11
- package/generator-adapter/node_modules/@inquirer/select/package.json +23 -21
- package/generator-adapter/node_modules/@inquirer/type/package.json +18 -16
- package/generator-adapter/node_modules/@yeoman/adapter/dist/adapter.d.ts +0 -3
- package/generator-adapter/node_modules/@yeoman/adapter/dist/adapter.js +1 -0
- package/generator-adapter/node_modules/@yeoman/adapter/dist/adapter.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/log.d.ts +0 -2
- package/generator-adapter/node_modules/@yeoman/adapter/dist/log.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/queued-adapter.d.ts +0 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/queued-adapter.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/testing/test-adapter.d.ts +0 -1
- package/generator-adapter/node_modules/@yeoman/adapter/dist/testing/test-adapter.js.map +1 -1
- package/generator-adapter/node_modules/@yeoman/adapter/package.json +11 -11
- package/generator-adapter/node_modules/ansi-styles/index.d.ts +341 -232
- package/generator-adapter/node_modules/ansi-styles/index.js +130 -190
- package/generator-adapter/node_modules/ansi-styles/license +1 -1
- package/generator-adapter/node_modules/ansi-styles/package.json +10 -8
- package/generator-adapter/node_modules/ansi-styles/readme.md +32 -53
- package/generator-adapter/node_modules/chalk/package.json +3 -3
- package/generator-adapter/node_modules/chalk/readme.md +25 -53
- package/generator-adapter/node_modules/chalk/source/index.d.ts +6 -1
- package/generator-adapter/node_modules/chalk/source/vendor/supports-color/browser.js +6 -2
- package/generator-adapter/node_modules/chalk/source/vendor/supports-color/index.js +10 -2
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/index.d.ts +4 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/index.js +111 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/types.d.ts +19 -0
- package/generator-adapter/node_modules/{p-queue/dist/options copy.js β fast-string-truncated-width/dist/types.js} +1 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/utils.d.ts +4 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/dist/utils.js +20 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/license +21 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/package.json +35 -0
- package/generator-adapter/node_modules/fast-string-truncated-width/readme.md +59 -0
- package/generator-adapter/node_modules/fast-string-width/dist/index.d.ts +4 -0
- package/generator-adapter/node_modules/fast-string-width/dist/index.js +14 -0
- package/generator-adapter/node_modules/fast-string-width/license +21 -0
- package/generator-adapter/node_modules/fast-string-width/package.json +34 -0
- package/generator-adapter/node_modules/fast-string-width/readme.md +42 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/LICENSE +23 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/README.md +26 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/lib/main.d.ts +6 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/lib/main.js +219 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/lib/main.js.map +1 -0
- package/generator-adapter/node_modules/fast-wrap-ansi/package.json +51 -0
- package/generator-adapter/node_modules/iconv-lite/lib/index.d.ts +114 -26
- package/generator-adapter/node_modules/iconv-lite/lib/index.js +39 -40
- package/generator-adapter/node_modules/iconv-lite/package.json +13 -2
- package/generator-adapter/node_modules/iconv-lite/types/encodings.d.ts +423 -0
- package/generator-adapter/node_modules/inquirer/dist/types.d.ts +12 -11
- package/generator-adapter/node_modules/inquirer/dist/ui/prompt.js +9 -1
- package/generator-adapter/node_modules/inquirer/dist/ui/skipped-renderer.d.ts +13 -0
- package/generator-adapter/node_modules/inquirer/dist/ui/skipped-renderer.js +57 -0
- package/generator-adapter/node_modules/inquirer/package.json +21 -19
- package/generator-adapter/node_modules/log-symbols/package.json +1 -1
- package/generator-adapter/node_modules/log-symbols/symbols.js +1 -1
- package/generator-adapter/node_modules/mem-fs/dist/index.d.ts +0 -2
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/LICENSE +21 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/README.md +447 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/index.js +346 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/lib/inspect-stream.js +13 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/lib/is-stream.js +15 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/lib/normalize.js +9 -0
- package/generator-adapter/node_modules/mem-fs/node_modules/vinyl/package.json +59 -0
- package/generator-adapter/node_modules/mem-fs/package.json +9 -9
- package/generator-adapter/node_modules/ora/index.d.ts +3 -1
- package/generator-adapter/node_modules/ora/index.js +299 -109
- package/generator-adapter/node_modules/ora/package.json +3 -4
- package/generator-adapter/node_modules/ora/readme.md +24 -0
- package/generator-adapter/node_modules/p-queue/dist/index.js +145 -22
- package/generator-adapter/node_modules/p-queue/dist/options.d.ts +17 -1
- package/generator-adapter/node_modules/p-queue/package.json +1 -1
- package/generator-adapter/node_modules/p-queue/readme.md +32 -1
- package/generator-adapter/node_modules/stdin-discarder/index.js +50 -22
- package/generator-adapter/node_modules/stdin-discarder/package.json +1 -1
- package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/package.json +3 -3
- package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/readme.md +53 -25
- package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/index.d.ts +1 -6
- package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/vendor/supports-color/browser.js +2 -6
- package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/vendor/supports-color/index.js +2 -10
- package/generator-adapter/package.json +2 -2
- package/package.json +4 -4
- package/transports/websocket.d.ts +5 -0
- package/transports/websocket.js +25 -13
- package/transports/websocket.js.map +1 -1
- package/generator-adapter/node_modules/emoji-regex/LICENSE-MIT.txt +0 -20
- package/generator-adapter/node_modules/emoji-regex/README.md +0 -107
- package/generator-adapter/node_modules/emoji-regex/index.d.ts +0 -3
- package/generator-adapter/node_modules/emoji-regex/index.js +0 -4
- package/generator-adapter/node_modules/emoji-regex/index.mjs +0 -4
- package/generator-adapter/node_modules/emoji-regex/package.json +0 -45
- package/generator-adapter/node_modules/iconv-lite/Changelog.md +0 -236
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/index.d.ts +0 -345
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/index.js +0 -163
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/license +0 -9
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/package.json +0 -56
- package/generator-adapter/node_modules/jake/node_modules/ansi-styles/readme.md +0 -152
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/browser-symbols.js +0 -4
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/browser.js +0 -1
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/index.d.ts +0 -22
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/index.js +0 -1
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/license +0 -9
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/package.json +0 -60
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/readme.md +0 -39
- package/generator-adapter/node_modules/ora/node_modules/log-symbols/symbols.js +0 -14
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/index.d.ts +0 -15
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/index.js +0 -14
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/license +0 -9
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/package.json +0 -59
- package/generator-adapter/node_modules/ora/node_modules/strip-ansi/readme.md +0 -37
- package/generator-adapter/node_modules/p-queue/dist/options copy.d.ts +0 -121
- package/generator-adapter/node_modules/wrap-ansi/index.d.ts +0 -41
- package/generator-adapter/node_modules/wrap-ansi/index.js +0 -222
- package/generator-adapter/node_modules/wrap-ansi/license +0 -9
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/index.d.ts +0 -39
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/index.js +0 -82
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/license +0 -9
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/package.json +0 -64
- package/generator-adapter/node_modules/wrap-ansi/node_modules/string-width/readme.md +0 -66
- package/generator-adapter/node_modules/wrap-ansi/package.json +0 -69
- package/generator-adapter/node_modules/wrap-ansi/readme.md +0 -75
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/license +0 -0
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/index.js +0 -0
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/utilities.js +0 -0
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +0 -0
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -0
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/vendor/supports-color/browser.d.ts +0 -0
- /package/generator-adapter/node_modules/{ora β yeoman-generator}/node_modules/chalk/source/vendor/supports-color/index.d.ts +0 -0
|
@@ -12,59 +12,13 @@
|
|
|
12
12
|
[](https://codecov.io/gh/chalk/chalk)
|
|
13
13
|
[](https://www.npmjs.com/package/chalk?activeTab=dependents)
|
|
14
14
|
[](https://www.npmjs.com/package/chalk)
|
|
15
|
-
[](https://repl.it/github/chalk/chalk)
|
|
16
15
|
|
|
17
16
|

|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<div align="center">
|
|
24
|
-
<p>
|
|
25
|
-
<p>
|
|
26
|
-
<sup>
|
|
27
|
-
Sindre Sorhus' open source work is supported by the community on <a href="https://github.com/sponsors/sindresorhus">GitHub Sponsors</a>
|
|
28
|
-
</sup>
|
|
29
|
-
</p>
|
|
30
|
-
<sup>Special thanks to:</sup>
|
|
31
|
-
<br>
|
|
32
|
-
<br>
|
|
33
|
-
<a href="https://standardresume.co/tech">
|
|
34
|
-
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="160">
|
|
35
|
-
</a>
|
|
36
|
-
<br>
|
|
37
|
-
<br>
|
|
38
|
-
<a href="https://retool.com/?utm_campaign=sindresorhus">
|
|
39
|
-
<img src="https://sindresorhus.com/assets/thanks/retool-logo.svg" width="230">
|
|
40
|
-
</a>
|
|
41
|
-
<br>
|
|
42
|
-
<br>
|
|
43
|
-
<a href="https://strapi.io/?ref=sindresorhus">
|
|
44
|
-
<div>
|
|
45
|
-
<img src="https://sindresorhus.com/assets/thanks/strapi-logo-white-bg.png" width="220" alt="Strapi">
|
|
46
|
-
</div>
|
|
47
|
-
<b>Strapi is the leading open-source headless CMS.</b>
|
|
48
|
-
<div>
|
|
49
|
-
<sup>Itβs 100% JavaScript, fully customizable, and developer-first.</sup>
|
|
50
|
-
</div>
|
|
51
|
-
</a>
|
|
52
|
-
<br>
|
|
53
|
-
<br>
|
|
54
|
-
<a href="https://www.stackaid.us/?utm_campaign=sindre">
|
|
55
|
-
<div>
|
|
56
|
-
<img src="https://sindresorhus.com/assets/thanks/stackaid-logo.png" width="230" alt="StackAid">
|
|
57
|
-
</div>
|
|
58
|
-
<b>Fund your open source dependencies</b>
|
|
59
|
-
</a>
|
|
60
|
-
<br>
|
|
61
|
-
<br>
|
|
62
|
-
</p>
|
|
63
|
-
</div>
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
<br>
|
|
18
|
+
## Info
|
|
19
|
+
|
|
20
|
+
- [Why not switch to a smaller coloring package?](https://github.com/chalk/chalk?tab=readme-ov-file#why-not-switch-to-a-smaller-coloring-package)
|
|
21
|
+
- See [yoctocolors](https://github.com/sindresorhus/yoctocolors) for a smaller alternative
|
|
68
22
|
|
|
69
23
|
## Highlights
|
|
70
24
|
|
|
@@ -77,7 +31,7 @@
|
|
|
77
31
|
- Doesn't extend `String.prototype`
|
|
78
32
|
- Clean and focused
|
|
79
33
|
- Actively maintained
|
|
80
|
-
- [Used by ~
|
|
34
|
+
- [Used by ~115,000 packages](https://www.npmjs.com/browse/depended/chalk) as of July 4, 2024
|
|
81
35
|
|
|
82
36
|
## Install
|
|
83
37
|
|
|
@@ -297,9 +251,25 @@ Since Chrome 69, ANSI escape codes are natively supported in the developer conso
|
|
|
297
251
|
|
|
298
252
|
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
|
|
299
253
|
|
|
300
|
-
##
|
|
254
|
+
## FAQ
|
|
255
|
+
|
|
256
|
+
### Why not switch to a smaller coloring package?
|
|
257
|
+
|
|
258
|
+
Chalk may be larger, but there is a reason for that. It offers a more user-friendly API, well-documented types, supports millions of colors, and covers edge cases that smaller alternatives miss. Chalk is mature, reliable, and built to last.
|
|
259
|
+
|
|
260
|
+
But beyond the technical aspects, there's something more critical: trust and long-term maintenance. I have been active in open source for over a decade, and I'm committed to keeping Chalk maintained. Smaller packages might seem appealing now, but there's no guarantee they will be around for the long term, or that they won't become malicious over time.
|
|
261
|
+
|
|
262
|
+
Chalk is also likely already in your dependency tree (since 100K+ packages depend on it), so switching wonβt save spaceβin fact, it might increase it. npm deduplicates dependencies, so multiple Chalk instances turn into one, but adding another package alongside it will increase your overall size.
|
|
301
263
|
|
|
302
|
-
|
|
264
|
+
If the goal is to clean up the ecosystem, switching away from Chalk wonβt even make a dent. The real problem lies with packages that have very deep dependency trees (for example, those including a lot of polyfills). Chalk has no dependencies. It's better to focus on impactful changes rather than minor optimizations.
|
|
265
|
+
|
|
266
|
+
If absolute package size is important to you, I also maintain [yoctocolors](https://github.com/sindresorhus/yoctocolors), one of the smallest color packages out there.
|
|
267
|
+
|
|
268
|
+
*\- [Sindre](https://github.com/sindresorhus)*
|
|
269
|
+
|
|
270
|
+
### But the smaller coloring package has benchmarks showing it is faster
|
|
271
|
+
|
|
272
|
+
[Micro-benchmarks are flawed](https://sindresorhus.com/blog/micro-benchmark-fallacy) because they measure performance in unrealistic, isolated scenarios, often giving a distorted view of real-world performance. Don't believe marketing fluff. All the coloring packages are more than fast enough.
|
|
303
273
|
|
|
304
274
|
## Related
|
|
305
275
|
|
|
@@ -319,6 +289,8 @@ If you're on Windows, do yourself a favor and use [Windows Terminal](https://git
|
|
|
319
289
|
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
|
|
320
290
|
- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
|
|
321
291
|
|
|
292
|
+
*(Not accepting additional entries)*
|
|
293
|
+
|
|
322
294
|
## Maintainers
|
|
323
295
|
|
|
324
296
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// TODO: Make it this when TS suports that.
|
|
2
2
|
// import {ModifierName, ForegroundColor, BackgroundColor, ColorName} from '#ansi-styles';
|
|
3
3
|
// import {ColorInfo, ColorSupportLevel} from '#supports-color';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
ModifierName,
|
|
6
|
+
ForegroundColorName,
|
|
7
|
+
BackgroundColorName,
|
|
8
|
+
ColorName,
|
|
9
|
+
} from './vendor/ansi-styles/index.js';
|
|
5
10
|
import {ColorInfo, ColorSupportLevel} from './vendor/supports-color/index.js';
|
|
6
11
|
|
|
7
12
|
export interface Options {
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
2
|
|
|
3
3
|
const level = (() => {
|
|
4
|
-
if (navigator
|
|
4
|
+
if (!('navigator' in globalThis)) {
|
|
5
|
+
return 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (globalThis.navigator.userAgentData) {
|
|
5
9
|
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
|
6
10
|
if (brand && brand.version > 93) {
|
|
7
11
|
return 3;
|
|
8
12
|
}
|
|
9
13
|
}
|
|
10
14
|
|
|
11
|
-
if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
|
|
15
|
+
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
12
16
|
return 1;
|
|
13
17
|
}
|
|
14
18
|
|
|
@@ -112,11 +112,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
if ('CI' in env) {
|
|
115
|
-
if ('GITHUB_ACTIONS'
|
|
115
|
+
if (['GITHUB_ACTIONS', 'GITEA_ACTIONS', 'CIRCLECI'].some(key => key in env)) {
|
|
116
116
|
return 3;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
if (['TRAVIS', '
|
|
119
|
+
if (['TRAVIS', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
120
120
|
return 1;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -135,6 +135,14 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
|
|
|
135
135
|
return 3;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
if (env.TERM === 'xterm-ghostty') {
|
|
139
|
+
return 3;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (env.TERM === 'wezterm') {
|
|
143
|
+
return 3;
|
|
144
|
+
}
|
|
145
|
+
|
|
138
146
|
if ('TERM_PROGRAM' in env) {
|
|
139
147
|
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
140
148
|
|
|
@@ -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,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,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.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fast-string-width",
|
|
3
|
+
"repository": "github:fabiospampinato/fast-string-width",
|
|
4
|
+
"description": "A fast function for calculating the visual width of a string once printed to the terminal.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "3.0.2",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"exports": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "tsex clean",
|
|
13
|
+
"compile": "tsex compile",
|
|
14
|
+
"compile:watch": "tsex compile --watch",
|
|
15
|
+
"test": "tsex test",
|
|
16
|
+
"test:watch": "tsex test --watch",
|
|
17
|
+
"prepublishOnly": "tsex prepare"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"fast",
|
|
21
|
+
"string",
|
|
22
|
+
"width",
|
|
23
|
+
"cli",
|
|
24
|
+
"terminal"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"fast-string-truncated-width": "^3.0.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"fava": "^0.3.4",
|
|
31
|
+
"tsex": "^4.0.2",
|
|
32
|
+
"typescript": "^5.7.3"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Fast String Width
|
|
2
|
+
|
|
3
|
+
A fast function for calculating the visual width of a string once printed to the terminal.
|
|
4
|
+
|
|
5
|
+
See [`fast-string-truncated-width`](https://github.com/fabiospampinato/fast-string-truncated-width) for a lower-level version of this.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install fast-string-width
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import fastStringWidth from 'fast-string-width';
|
|
17
|
+
|
|
18
|
+
// The width of various classes of characters is configurable
|
|
19
|
+
|
|
20
|
+
const options = {
|
|
21
|
+
controlWidth: 0,
|
|
22
|
+
tabWidth: 8,
|
|
23
|
+
emojiWidth: 2,
|
|
24
|
+
regularWidth: 1,
|
|
25
|
+
wideWidth: 2
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Calculating the visual width of some strings
|
|
29
|
+
|
|
30
|
+
fastStringWidth ( 'hello', options ); // => 5
|
|
31
|
+
fastStringWidth ( '\x1b[31mhello', options ); // => 5
|
|
32
|
+
fastStringWidth ( 'π¨βπ©βπ§βπ¦', options ); // => 2
|
|
33
|
+
fastStringWidth ( 'helloπ¨βπ©βπ§βπ¦', options ); // => 7
|
|
34
|
+
|
|
35
|
+
// Calculating the visual width while tweaking the width of emojis
|
|
36
|
+
|
|
37
|
+
fastStringWidth ( 'πΆπΆπ½', { ...options, emojiWidth: 1.5 } ); // => 3
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT Β© Fabio Spampinato
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 James Garbutt
|
|
4
|
+
|
|
5
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# fast-wrap-ansi
|
|
2
|
+
|
|
3
|
+
Wordwrap a string, taking ANSI escape codes into account.
|
|
4
|
+
|
|
5
|
+
A fast, light fork of the `wrap-ansi` package.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i -S fast-wrap-ansi
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import {wrapAnsi} from 'fast-wrap-ansi';
|
|
18
|
+
|
|
19
|
+
const str = 'This is a string with some \x1b[31mANSI\x1b[39m codes.';
|
|
20
|
+
const wrapped = wrapAnsi(str, 20);
|
|
21
|
+
console.log(wrapped);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT
|