@node-core/utils 7.1.0 → 7.2.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/components/metadata.js +2 -1
- package/lib/ci/build-types/test_build.js +3 -3
- package/lib/ci/failure_aggregator.js +2 -2
- package/lib/ci/run_ci.js +3 -2
- package/lib/cli.js +6 -6
- package/lib/figures.js +6 -6
- package/lib/prepare_security.js +20 -21
- package/lib/request.js +1 -1
- package/lib/update-v8/backport.js +3 -4
- package/lib/utils.js +4 -2
- package/lib/verbosity.js +2 -4
- package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/README.md +4 -4
- package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.d.mts +21 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/dist/index.mjs +46 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/LICENSE +22 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.d.ts +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/index.js +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.d.ts +35 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/inquirer.js +1 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.d.ts +34 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/dist/utils.js +2 -0
- package/node_modules/@listr2/prompt-adapter-inquirer/node_modules/@inquirer/type/package.json +88 -0
- package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/package.json +25 -20
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.d.ts +48 -3
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/base.js +58 -19
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/package.json +1 -1
- package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/readme.md +36 -1
- package/node_modules/ansi-regex/index.js +9 -4
- package/node_modules/ansi-regex/package.json +1 -1
- package/node_modules/ansi-regex/readme.md +6 -0
- package/node_modules/ansi-styles/index.d.ts +12 -12
- package/node_modules/ansi-styles/index.js +3 -3
- package/node_modules/ansi-styles/package.json +4 -4
- package/node_modules/cli-truncate/index.d.ts +3 -3
- package/node_modules/cli-truncate/index.js +40 -14
- package/node_modules/cli-truncate/node_modules/string-width/index.js +133 -15
- package/node_modules/cli-truncate/node_modules/string-width/package.json +4 -4
- package/node_modules/cli-truncate/node_modules/string-width/readme.md +1 -1
- package/node_modules/cli-truncate/package.json +7 -7
- package/node_modules/cli-truncate/readme.md +2 -3
- package/node_modules/ghauth/.github/dependabot.yml +11 -3
- package/node_modules/ghauth/.github/workflows/depsound.yml +33 -0
- package/node_modules/ghauth/.github/workflows/test-and-release.yml +4 -4
- package/node_modules/ghauth/CHANGELOG.md +60 -0
- package/node_modules/ghauth/package.json +30 -6
- package/node_modules/js-yaml/README.md +20 -187
- package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs +1008 -946
- package/node_modules/js-yaml/dist/browser/js-yaml.esm.min.mjs.map +1 -1
- package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js +29 -23
- package/node_modules/js-yaml/dist/browser/js-yaml.umd.min.js.map +1 -1
- package/node_modules/js-yaml/dist/js-yaml.cjs.js +1043 -583
- package/node_modules/js-yaml/dist/js-yaml.cjs.js.map +1 -1
- package/node_modules/js-yaml/dist/js-yaml.d.ts +877 -133
- package/node_modules/js-yaml/dist/js-yaml.mjs +995 -556
- package/node_modules/js-yaml/dist/js-yaml.mjs.map +1 -1
- package/node_modules/js-yaml/package.json +8 -7
- package/node_modules/listr2/dist/{index.d.cts → index.d.mts} +90 -60
- package/node_modules/listr2/dist/{index.js → index.mjs} +496 -373
- package/node_modules/listr2/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/listr2/node_modules/string-width/index.js +207 -0
- package/node_modules/listr2/node_modules/string-width/package.json +65 -0
- package/node_modules/listr2/node_modules/string-width/readme.md +66 -0
- package/node_modules/listr2/node_modules/wrap-ansi/index.d.ts +1 -1
- package/node_modules/listr2/node_modules/wrap-ansi/index.js +544 -116
- package/node_modules/listr2/node_modules/wrap-ansi/package.json +10 -13
- package/node_modules/listr2/node_modules/wrap-ansi/readme.md +2 -0
- package/node_modules/listr2/package.json +16 -19
- package/node_modules/log-update/index.d.ts +64 -1
- package/node_modules/log-update/index.js +268 -18
- package/node_modules/log-update/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/log-update/node_modules/string-width/index.js +207 -0
- package/node_modules/log-update/node_modules/string-width/package.json +65 -0
- package/node_modules/log-update/node_modules/string-width/readme.md +66 -0
- package/node_modules/log-update/node_modules/wrap-ansi/index.d.ts +1 -1
- package/node_modules/log-update/node_modules/wrap-ansi/index.js +544 -116
- package/node_modules/log-update/node_modules/wrap-ansi/package.json +10 -13
- package/node_modules/log-update/node_modules/wrap-ansi/readme.md +2 -0
- package/node_modules/log-update/package.json +14 -12
- package/node_modules/log-update/readme.md +61 -0
- package/node_modules/slice-ansi/index.d.ts +2 -2
- package/node_modules/slice-ansi/index.js +260 -112
- package/node_modules/slice-ansi/package.json +10 -9
- package/node_modules/slice-ansi/readme.md +3 -2
- package/node_modules/slice-ansi/tokenize-ansi.js +752 -0
- package/node_modules/smol-toml/README.md +205 -191
- package/node_modules/smol-toml/dist/date.d.ts +0 -1
- package/node_modules/smol-toml/dist/date.js +0 -1
- package/node_modules/smol-toml/dist/error.d.ts +0 -1
- package/node_modules/smol-toml/dist/error.js +0 -1
- package/node_modules/smol-toml/dist/extract.js +32 -65
- package/node_modules/smol-toml/dist/index.cjs +302 -288
- package/node_modules/smol-toml/dist/index.d.ts +0 -1
- package/node_modules/smol-toml/dist/index.js +0 -1
- package/node_modules/smol-toml/dist/parse.d.ts +1 -3
- package/node_modules/smol-toml/dist/parse.js +22 -21
- package/node_modules/smol-toml/dist/primitive.js +75 -76
- package/node_modules/smol-toml/dist/stringify.d.ts +0 -1
- package/node_modules/smol-toml/dist/stringify.js +43 -30
- package/node_modules/smol-toml/dist/struct.js +90 -93
- package/node_modules/smol-toml/dist/util.d.ts +1 -1
- package/node_modules/smol-toml/dist/util.js +36 -39
- package/node_modules/smol-toml/package.json +6 -6
- package/node_modules/strip-ansi/index.js +5 -0
- package/node_modules/strip-ansi/package.json +5 -5
- package/package.json +3 -9
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.cjs +0 -127
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.cts +0 -152
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.d.ts +0 -152
- package/node_modules/@listr2/prompt-adapter-enquirer/dist/index.js +0 -92
- package/node_modules/chalk/package.json +0 -92
- package/node_modules/chalk/readme.md +0 -331
- package/node_modules/chalk/source/index.d.ts +0 -437
- package/node_modules/chalk/source/index.js +0 -261
- package/node_modules/chalk/source/utilities.js +0 -33
- package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +0 -299
- package/node_modules/chalk/source/vendor/ansi-styles/index.js +0 -261
- package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +0 -1
- package/node_modules/chalk/source/vendor/supports-color/browser.js +0 -32
- package/node_modules/chalk/source/vendor/supports-color/index.d.ts +0 -55
- package/node_modules/chalk/source/vendor/supports-color/index.js +0 -206
- package/node_modules/colorette/LICENSE.md +0 -7
- package/node_modules/colorette/README.md +0 -134
- package/node_modules/colorette/index.cjs +0 -218
- package/node_modules/colorette/index.d.ts +0 -93
- package/node_modules/colorette/index.js +0 -150
- package/node_modules/colorette/package.json +0 -40
- package/node_modules/eventemitter3/LICENSE +0 -21
- package/node_modules/eventemitter3/README.md +0 -94
- package/node_modules/eventemitter3/dist/eventemitter3.esm.js +0 -347
- package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.esm.min.js.map +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.umd.js +0 -355
- package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js +0 -1
- package/node_modules/eventemitter3/dist/eventemitter3.umd.min.js.map +0 -1
- package/node_modules/eventemitter3/index.d.ts +0 -135
- package/node_modules/eventemitter3/index.js +0 -336
- package/node_modules/eventemitter3/index.mjs +0 -4
- package/node_modules/eventemitter3/package.json +0 -67
- package/node_modules/figures/index.d.ts +0 -279
- package/node_modules/figures/index.js +0 -292
- package/node_modules/figures/package.json +0 -49
- package/node_modules/figures/readme.md +0 -337
- package/node_modules/isexe/LICENSE.md +0 -55
- package/node_modules/isexe/README.md +0 -80
- package/node_modules/isexe/dist/commonjs/index.d.ts +0 -14
- package/node_modules/isexe/dist/commonjs/index.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/index.js +0 -56
- package/node_modules/isexe/dist/commonjs/index.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/index.min.js +0 -2
- package/node_modules/isexe/dist/commonjs/index.min.js.map +0 -7
- package/node_modules/isexe/dist/commonjs/options.d.ts +0 -32
- package/node_modules/isexe/dist/commonjs/options.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/options.js +0 -3
- package/node_modules/isexe/dist/commonjs/options.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/package.json +0 -3
- package/node_modules/isexe/dist/commonjs/posix.d.ts +0 -18
- package/node_modules/isexe/dist/commonjs/posix.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/posix.js +0 -67
- package/node_modules/isexe/dist/commonjs/posix.js.map +0 -1
- package/node_modules/isexe/dist/commonjs/win32.d.ts +0 -18
- package/node_modules/isexe/dist/commonjs/win32.d.ts.map +0 -1
- package/node_modules/isexe/dist/commonjs/win32.js +0 -63
- package/node_modules/isexe/dist/commonjs/win32.js.map +0 -1
- package/node_modules/isexe/dist/esm/index.d.ts +0 -14
- package/node_modules/isexe/dist/esm/index.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/index.js +0 -16
- package/node_modules/isexe/dist/esm/index.js.map +0 -1
- package/node_modules/isexe/dist/esm/index.min.js +0 -2
- package/node_modules/isexe/dist/esm/index.min.js.map +0 -7
- package/node_modules/isexe/dist/esm/options.d.ts +0 -32
- package/node_modules/isexe/dist/esm/options.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/options.js +0 -2
- package/node_modules/isexe/dist/esm/options.js.map +0 -1
- package/node_modules/isexe/dist/esm/package.json +0 -3
- package/node_modules/isexe/dist/esm/posix.d.ts +0 -18
- package/node_modules/isexe/dist/esm/posix.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/posix.js +0 -62
- package/node_modules/isexe/dist/esm/posix.js.map +0 -1
- package/node_modules/isexe/dist/esm/win32.d.ts +0 -18
- package/node_modules/isexe/dist/esm/win32.d.ts.map +0 -1
- package/node_modules/isexe/dist/esm/win32.js +0 -58
- package/node_modules/isexe/dist/esm/win32.js.map +0 -1
- package/node_modules/isexe/package.json +0 -78
- package/node_modules/listr2/dist/index.cjs +0 -2189
- package/node_modules/listr2/dist/index.d.ts +0 -1528
- package/node_modules/rfdc/.github/workflows/ci.yml +0 -21
- package/node_modules/rfdc/LICENSE +0 -15
- package/node_modules/rfdc/default.js +0 -3
- package/node_modules/rfdc/index.d.ts +0 -13
- package/node_modules/rfdc/index.js +0 -198
- package/node_modules/rfdc/index.test-d.ts +0 -13
- package/node_modules/rfdc/package.json +0 -73
- package/node_modules/rfdc/readme.md +0 -181
- package/node_modules/rfdc/test/index.js +0 -306
- package/node_modules/smol-toml/dist/date.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/date.js.map +0 -1
- package/node_modules/smol-toml/dist/error.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/error.js.map +0 -1
- package/node_modules/smol-toml/dist/extract.js.map +0 -1
- package/node_modules/smol-toml/dist/index.cjs.map +0 -1
- package/node_modules/smol-toml/dist/index.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/index.js.map +0 -1
- package/node_modules/smol-toml/dist/parse.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/parse.js.map +0 -1
- package/node_modules/smol-toml/dist/primitive.d.ts +0 -29
- package/node_modules/smol-toml/dist/primitive.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/primitive.js.map +0 -1
- package/node_modules/smol-toml/dist/stringify.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/stringify.js.map +0 -1
- package/node_modules/smol-toml/dist/struct.js.map +0 -1
- package/node_modules/smol-toml/dist/util.d.ts.map +0 -1
- package/node_modules/smol-toml/dist/util.js.map +0 -1
- package/node_modules/smol-toml/src/date.ts +0 -152
- package/node_modules/smol-toml/src/error.ts +0 -77
- package/node_modules/smol-toml/src/extract.ts +0 -113
- package/node_modules/smol-toml/src/index.ts +0 -42
- package/node_modules/smol-toml/src/parse.ts +0 -184
- package/node_modules/smol-toml/src/primitive.ts +0 -249
- package/node_modules/smol-toml/src/stringify.ts +0 -191
- package/node_modules/smol-toml/src/struct.ts +0 -202
- package/node_modules/smol-toml/src/util.ts +0 -106
- package/node_modules/which/LICENSE +0 -15
- package/node_modules/which/README.md +0 -51
- package/node_modules/which/bin/which.js +0 -52
- package/node_modules/which/lib/index.js +0 -111
- package/node_modules/which/package.json +0 -52
- /package/node_modules/@listr2/{prompt-adapter-enquirer → prompt-adapter-inquirer}/LICENSE +0 -0
- /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.d.ts +0 -0
- /package/node_modules/{log-update/node_modules/ansi-escapes → ansi-escapes}/index.js +0 -0
- /package/node_modules/{chalk → ansi-escapes}/license +0 -0
- /package/node_modules/{figures → listr2/node_modules/string-width}/license +0 -0
- /package/node_modules/log-update/node_modules/{ansi-escapes → string-width}/license +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import stripAnsi from 'strip-ansi';
|
|
2
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Logic:
|
|
6
|
+
- Segment graphemes to match how terminals render clusters.
|
|
7
|
+
- Width rules:
|
|
8
|
+
1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
|
|
9
|
+
2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
|
|
10
|
+
3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
|
|
11
|
+
4. Hangul jamo collapse each standard modern Hangul L+V or L+V+T syllable piece to width 2.
|
|
12
|
+
Unmatched repeated leading/vowel/trailing jamo stay additive because that matches how the terminals we target render them.
|
|
13
|
+
5. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing spacing marks and Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const segmenter = new Intl.Segmenter();
|
|
17
|
+
|
|
18
|
+
// Whole-cluster zero-width
|
|
19
|
+
const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
|
|
20
|
+
|
|
21
|
+
// Pick the base scalar if the cluster starts with Prepend/Format/Marks
|
|
22
|
+
const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]+/v;
|
|
23
|
+
const spacingMarkRegex = /\p{Spacing_Mark}/v;
|
|
24
|
+
|
|
25
|
+
// RGI emoji sequences
|
|
26
|
+
const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
|
|
27
|
+
|
|
28
|
+
// Detect minimally-qualified/unqualified emoji sequences (missing VS16 but still render as double-width)
|
|
29
|
+
const unqualifiedKeycapRegex = /^[\d#*]\u20E3$/;
|
|
30
|
+
const extendedPictographicRegex = /\p{Extended_Pictographic}/gu;
|
|
31
|
+
|
|
32
|
+
function isDoubleWidthNonRgiEmojiSequence(segment) {
|
|
33
|
+
// Real emoji clusters are < 30 chars; guard against pathological input
|
|
34
|
+
if (segment.length > 50) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (unqualifiedKeycapRegex.test(segment)) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ZWJ sequences with 2+ Extended_Pictographic
|
|
43
|
+
if (segment.includes('\u200D')) {
|
|
44
|
+
const pictographics = segment.match(extendedPictographicRegex);
|
|
45
|
+
return pictographics !== null && pictographics.length >= 2;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function baseVisible(segment) {
|
|
52
|
+
return segment.replace(leadingNonPrintingRegex, '');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isZeroWidthCluster(segment) {
|
|
56
|
+
return zeroWidthClusterRegex.test(segment);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isHangulLeadingJamo(codePoint) {
|
|
60
|
+
return (codePoint >= 0x11_00 && codePoint <= 0x11_5F)
|
|
61
|
+
|| (codePoint >= 0xA9_60 && codePoint <= 0xA9_7C);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isHangulVowelJamo(codePoint) {
|
|
65
|
+
return (codePoint >= 0x11_60 && codePoint <= 0x11_A7)
|
|
66
|
+
|| (codePoint >= 0xD7_B0 && codePoint <= 0xD7_C6);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isHangulTrailingJamo(codePoint) {
|
|
70
|
+
return (codePoint >= 0x11_A8 && codePoint <= 0x11_FF)
|
|
71
|
+
|| (codePoint >= 0xD7_CB && codePoint <= 0xD7_FB);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isHangulJamo(codePoint) {
|
|
75
|
+
return isHangulLeadingJamo(codePoint)
|
|
76
|
+
|| isHangulVowelJamo(codePoint)
|
|
77
|
+
|| isHangulTrailingJamo(codePoint);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
|
|
81
|
+
const codePoints = [];
|
|
82
|
+
|
|
83
|
+
for (const character of visibleSegment) {
|
|
84
|
+
if (zeroWidthClusterRegex.test(character)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
codePoints.push(character.codePointAt(0));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (codePoints.length === 0) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let width = 0;
|
|
96
|
+
|
|
97
|
+
for (let index = 0; index < codePoints.length; index++) {
|
|
98
|
+
const codePoint = codePoints[index];
|
|
99
|
+
if (!isHangulJamo(codePoint)) {
|
|
100
|
+
if (width === 0) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Mixed cluster (e.g., L + precomposed syllable): use EAW for non-jamo remainder
|
|
105
|
+
for (let remaining = index; remaining < codePoints.length; remaining++) {
|
|
106
|
+
width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return width;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Modern Hangul L+V(+T) shapes as one syllable block. Unmatched jamo stay additive:
|
|
113
|
+
// U+1100 U+1100 U+1161 => U+1100 + (U+1100 U+1161) => 2 + 2.
|
|
114
|
+
if (
|
|
115
|
+
isHangulLeadingJamo(codePoint)
|
|
116
|
+
&& isHangulVowelJamo(codePoints[index + 1])
|
|
117
|
+
) {
|
|
118
|
+
width += 2;
|
|
119
|
+
index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return width;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function trailingWidth(visibleSegment, eastAsianWidthOptions) {
|
|
130
|
+
let extra = 0;
|
|
131
|
+
let first = true;
|
|
132
|
+
|
|
133
|
+
for (const character of visibleSegment) {
|
|
134
|
+
if (first) {
|
|
135
|
+
first = false;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (
|
|
140
|
+
spacingMarkRegex.test(character)
|
|
141
|
+
|| (character >= '\uFF00' && character <= '\uFFEF')
|
|
142
|
+
) {
|
|
143
|
+
extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return extra;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default function stringWidth(input, options = {}) {
|
|
151
|
+
if (typeof input !== 'string' || input.length === 0) {
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const {
|
|
156
|
+
ambiguousIsNarrow = true,
|
|
157
|
+
countAnsiEscapeCodes = false,
|
|
158
|
+
} = options;
|
|
159
|
+
|
|
160
|
+
let string = input;
|
|
161
|
+
|
|
162
|
+
// Avoid calling stripAnsi when there are no ANSI escape sequences (ESC = 0x1B, CSI = 0x9B)
|
|
163
|
+
if (!countAnsiEscapeCodes && (string.includes('\u001B') || string.includes('\u009B'))) {
|
|
164
|
+
string = stripAnsi(string);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (string.length === 0) {
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Fast path: printable ASCII (0x20–0x7E) needs no segmenter, regex, or EAW lookup — width equals length.
|
|
172
|
+
if (/^[\u0020-\u007E]*$/.test(string)) {
|
|
173
|
+
return string.length;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let width = 0;
|
|
177
|
+
const eastAsianWidthOptions = {ambiguousAsWide: !ambiguousIsNarrow};
|
|
178
|
+
|
|
179
|
+
for (const {segment} of segmenter.segment(string)) {
|
|
180
|
+
// Zero-width / non-printing clusters
|
|
181
|
+
if (isZeroWidthCluster(segment)) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Emoji width logic
|
|
186
|
+
if (rgiEmojiRegex.test(segment) || isDoubleWidthNonRgiEmojiSequence(segment)) {
|
|
187
|
+
width += 2;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const visibleSegment = baseVisible(segment);
|
|
192
|
+
const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
|
|
193
|
+
if (hangulWidth !== undefined) {
|
|
194
|
+
width += hangulWidth;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Everything else: EAW of the cluster’s first visible scalar
|
|
199
|
+
const codePoint = visibleSegment.codePointAt(0);
|
|
200
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
201
|
+
|
|
202
|
+
// Add width for trailing spacing marks and Halfwidth/Fullwidth Forms (e.g., ゙, ゚, ー)
|
|
203
|
+
width += trailingWidth(visibleSegment, eastAsianWidthOptions);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return width;
|
|
207
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "string-width",
|
|
3
|
+
"version": "8.2.2",
|
|
4
|
+
"description": "Get the visual width of a string - the number of columns required to display it",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "sindresorhus/string-width",
|
|
7
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "Sindre Sorhus",
|
|
10
|
+
"email": "sindresorhus@gmail.com",
|
|
11
|
+
"url": "https://sindresorhus.com"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"default": "./index.js"
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=20"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "xo && ava && tsd"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"index.d.ts"
|
|
28
|
+
],
|
|
29
|
+
"keywords": [
|
|
30
|
+
"string",
|
|
31
|
+
"character",
|
|
32
|
+
"unicode",
|
|
33
|
+
"width",
|
|
34
|
+
"visual",
|
|
35
|
+
"column",
|
|
36
|
+
"columns",
|
|
37
|
+
"fullwidth",
|
|
38
|
+
"full-width",
|
|
39
|
+
"wcwidth",
|
|
40
|
+
"wcswidth",
|
|
41
|
+
"full",
|
|
42
|
+
"ansi",
|
|
43
|
+
"escape",
|
|
44
|
+
"codes",
|
|
45
|
+
"cli",
|
|
46
|
+
"command-line",
|
|
47
|
+
"terminal",
|
|
48
|
+
"console",
|
|
49
|
+
"cjk",
|
|
50
|
+
"chinese",
|
|
51
|
+
"japanese",
|
|
52
|
+
"korean",
|
|
53
|
+
"fixed-width",
|
|
54
|
+
"east-asian-width"
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"get-east-asian-width": "^1.5.0",
|
|
58
|
+
"strip-ansi": "^7.1.2"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"ava": "^6.4.1",
|
|
62
|
+
"tsd": "^0.33.0",
|
|
63
|
+
"xo": "^1.2.3"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# string-width
|
|
2
|
+
|
|
3
|
+
> Get the visual width of a string - the number of columns required to display it
|
|
4
|
+
|
|
5
|
+
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and do not affect the width.
|
|
6
|
+
|
|
7
|
+
Useful to be able to measure the actual width of command-line output.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install string-width
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import stringWidth from 'string-width';
|
|
19
|
+
|
|
20
|
+
stringWidth('a');
|
|
21
|
+
//=> 1
|
|
22
|
+
|
|
23
|
+
stringWidth('古');
|
|
24
|
+
//=> 2
|
|
25
|
+
|
|
26
|
+
stringWidth('\u001B[1m古\u001B[22m');
|
|
27
|
+
//=> 2
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
### stringWidth(string, options?)
|
|
33
|
+
|
|
34
|
+
#### string
|
|
35
|
+
|
|
36
|
+
Type: `string`
|
|
37
|
+
|
|
38
|
+
The string to be counted.
|
|
39
|
+
|
|
40
|
+
#### options
|
|
41
|
+
|
|
42
|
+
Type: `object`
|
|
43
|
+
|
|
44
|
+
##### ambiguousIsNarrow
|
|
45
|
+
|
|
46
|
+
Type: `boolean`\
|
|
47
|
+
Default: `true`
|
|
48
|
+
|
|
49
|
+
Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).
|
|
50
|
+
|
|
51
|
+
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). **If the context cannot be established reliably, they should be treated as narrow characters by default.**
|
|
52
|
+
> - http://www.unicode.org/reports/tr11/
|
|
53
|
+
|
|
54
|
+
##### countAnsiEscapeCodes
|
|
55
|
+
|
|
56
|
+
Type: `boolean`\
|
|
57
|
+
Default: `false`
|
|
58
|
+
|
|
59
|
+
Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.
|
|
60
|
+
|
|
61
|
+
## Related
|
|
62
|
+
|
|
63
|
+
- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
|
|
64
|
+
- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
|
|
65
|
+
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
|
|
66
|
+
- [get-east-asian-width](https://github.com/sindresorhus/get-east-asian-width) - Determine the East Asian Width of a Unicode character
|
|
@@ -24,7 +24,7 @@ export type Options = {
|
|
|
24
24
|
/**
|
|
25
25
|
Wrap words to the specified column width.
|
|
26
26
|
|
|
27
|
-
@param string - A string with ANSI escape codes, like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.
|
|
27
|
+
@param string - A string with ANSI escape codes, like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`. Tab characters are expanded to spaces using 8-column tab stops before wrapping.
|
|
28
28
|
@param columns - The number of columns to wrap the text to.
|
|
29
29
|
|
|
30
30
|
@example
|