@depup/string-width 8.2.0-depup.0 → 8.3.0-depup.0

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 CHANGED
@@ -13,15 +13,16 @@ npm install @depup/string-width
13
13
 
14
14
  | Field | Value |
15
15
  |-------|-------|
16
- | Original | [string-width](https://www.npmjs.com/package/string-width) @ 8.2.0 |
17
- | Processed | 2026-03-19 |
16
+ | Original | [string-width](https://www.npmjs.com/package/string-width) @ 8.3.0 |
17
+ | Processed | 2026-09-27 |
18
18
  | Smoke test | passed |
19
- | Deps updated | 1 |
19
+ | Deps updated | 2 |
20
20
 
21
21
  ## Dependency Changes
22
22
 
23
23
  | Dependency | From | To |
24
24
  |------------|------|-----|
25
+ | get-east-asian-width | ^1.5.0 | ^1.7.0 |
25
26
  | strip-ansi | ^7.1.2 | ^7.2.0 |
26
27
 
27
28
  ---
package/changes.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "bumped": {
3
+ "get-east-asian-width": {
4
+ "from": "^1.5.0",
5
+ "to": "^1.7.0"
6
+ },
3
7
  "strip-ansi": {
4
8
  "from": "^7.1.2",
5
9
  "to": "^7.2.0"
6
10
  }
7
11
  },
8
- "timestamp": "2026-03-19T03:33:16.428Z",
9
- "totalUpdated": 1
12
+ "timestamp": "2026-09-27T01:04:23.363Z",
13
+ "totalUpdated": 2
10
14
  }
package/index.js CHANGED
@@ -5,19 +5,20 @@ import {eastAsianWidth} from 'get-east-asian-width';
5
5
  Logic:
6
6
  - Segment graphemes to match how terminals render clusters.
7
7
  - Width rules:
8
- 1. Skip non-printing clusters (Default_Ignorable, Control, pure Mark, lone Surrogates). Tabs are ignored by design.
8
+ 1. Skip non-printing clusters (Default_Ignorable, Control, pure nonspacing/enclosing Mark, lone Surrogates). Tabs are ignored by design.
9
9
  2. RGI emoji clusters (\p{RGI_Emoji}) are double-width.
10
10
  3. Minimally-qualified/unqualified emoji clusters (ZWJ sequences with 2+ Extended_Pictographic, or keycap sequences) are double-width.
11
- 4. Otherwise use East Asian Width of the cluster's first visible code point, and add widths for trailing Halfwidth/Fullwidth Forms within the same cluster (e.g., dakuten/handakuten/prolonged sound mark).
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).
12
14
  */
13
15
 
14
16
  const segmenter = new Intl.Segmenter();
15
17
 
16
- // Whole-cluster zero-width
17
- const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Mark}|\p{Surrogate})+$/v;
18
-
19
- // Pick the base scalar if the cluster starts with Prepend/Format/Marks
20
- const leadingNonPrintingRegex = /^[\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Mark}\p{Surrogate}]+/v;
18
+ // Matches a visible (printing) character. Used to find the base scalar of a cluster (skipping leading Prepend/Format/Marks) and to detect whole-cluster zero-width.
19
+ // Intentionally a single negated class without a quantifier: a repeated pattern like `^(?:…|…)+$` backtracks exponentially on overlapping properties, and even `^[…]+$` overflows V8's backtrack stack (RangeError) on clusters with millions of marks.
20
+ const visibleCharacterRegex = /[^\p{Default_Ignorable_Code_Point}\p{Control}\p{Format}\p{Nonspacing_Mark}\p{Enclosing_Mark}\p{Surrogate}]/v;
21
+ const spacingMarkRegex = /\p{Spacing_Mark}/v;
21
22
 
22
23
  // RGI emoji sequences
23
24
  const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
@@ -45,21 +46,97 @@ function isDoubleWidthNonRgiEmojiSequence(segment) {
45
46
  return false;
46
47
  }
47
48
 
49
+ // Returns the cluster starting at its first visible character, or `undefined` if the whole cluster is zero-width.
48
50
  function baseVisible(segment) {
49
- return segment.replace(leadingNonPrintingRegex, '');
51
+ const index = segment.search(visibleCharacterRegex);
52
+ return index === -1 ? undefined : segment.slice(index);
50
53
  }
51
54
 
52
- function isZeroWidthCluster(segment) {
53
- return zeroWidthClusterRegex.test(segment);
55
+ function isHangulLeadingJamo(codePoint) {
56
+ return (codePoint >= 0x11_00 && codePoint <= 0x11_5F)
57
+ || (codePoint >= 0xA9_60 && codePoint <= 0xA9_7C);
54
58
  }
55
59
 
56
- function trailingHalfwidthWidth(segment, eastAsianWidthOptions) {
57
- let extra = 0;
58
- if (segment.length > 1) {
59
- for (const char of segment.slice(1)) {
60
- if (char >= '\uFF00' && char <= '\uFFEF') {
61
- extra += eastAsianWidth(char.codePointAt(0), eastAsianWidthOptions);
60
+ function isHangulVowelJamo(codePoint) {
61
+ return (codePoint >= 0x11_60 && codePoint <= 0x11_A7)
62
+ || (codePoint >= 0xD7_B0 && codePoint <= 0xD7_C6);
63
+ }
64
+
65
+ function isHangulTrailingJamo(codePoint) {
66
+ return (codePoint >= 0x11_A8 && codePoint <= 0x11_FF)
67
+ || (codePoint >= 0xD7_CB && codePoint <= 0xD7_FB);
68
+ }
69
+
70
+ function isHangulJamo(codePoint) {
71
+ return isHangulLeadingJamo(codePoint)
72
+ || isHangulVowelJamo(codePoint)
73
+ || isHangulTrailingJamo(codePoint);
74
+ }
75
+
76
+ function hangulClusterWidth(visibleSegment, eastAsianWidthOptions) {
77
+ const codePoints = [];
78
+
79
+ for (const character of visibleSegment) {
80
+ if (!visibleCharacterRegex.test(character)) {
81
+ continue;
82
+ }
83
+
84
+ codePoints.push(character.codePointAt(0));
85
+ }
86
+
87
+ if (codePoints.length === 0) {
88
+ return undefined;
89
+ }
90
+
91
+ let width = 0;
92
+
93
+ for (let index = 0; index < codePoints.length; index++) {
94
+ const codePoint = codePoints[index];
95
+ if (!isHangulJamo(codePoint)) {
96
+ if (width === 0) {
97
+ return undefined;
62
98
  }
99
+
100
+ // Mixed cluster (e.g., L + precomposed syllable): use EAW for non-jamo remainder
101
+ for (let remaining = index; remaining < codePoints.length; remaining++) {
102
+ width += eastAsianWidth(codePoints[remaining], eastAsianWidthOptions);
103
+ }
104
+
105
+ return width;
106
+ }
107
+
108
+ // Modern Hangul L+V(+T) shapes as one syllable block. Unmatched jamo stay additive:
109
+ // U+1100 U+1100 U+1161 => U+1100 + (U+1100 U+1161) => 2 + 2.
110
+ if (
111
+ isHangulLeadingJamo(codePoint)
112
+ && isHangulVowelJamo(codePoints[index + 1])
113
+ ) {
114
+ width += 2;
115
+ index += isHangulTrailingJamo(codePoints[index + 2]) ? 2 : 1;
116
+ continue;
117
+ }
118
+
119
+ width += eastAsianWidth(codePoint, eastAsianWidthOptions);
120
+ }
121
+
122
+ return width;
123
+ }
124
+
125
+ function trailingWidth(visibleSegment, eastAsianWidthOptions) {
126
+ let extra = 0;
127
+ let first = true;
128
+
129
+ for (const character of visibleSegment) {
130
+ if (first) {
131
+ first = false;
132
+ continue;
133
+ }
134
+
135
+ if (
136
+ spacingMarkRegex.test(character)
137
+ || (character >= '\uFF00' && character <= '\uFFEF')
138
+ ) {
139
+ extra += eastAsianWidth(character.codePointAt(0), eastAsianWidthOptions);
63
140
  }
64
141
  }
65
142
 
@@ -97,7 +174,8 @@ export default function stringWidth(input, options = {}) {
97
174
 
98
175
  for (const {segment} of segmenter.segment(string)) {
99
176
  // Zero-width / non-printing clusters
100
- if (isZeroWidthCluster(segment)) {
177
+ const visibleSegment = baseVisible(segment);
178
+ if (visibleSegment === undefined) {
101
179
  continue;
102
180
  }
103
181
 
@@ -107,12 +185,18 @@ export default function stringWidth(input, options = {}) {
107
185
  continue;
108
186
  }
109
187
 
188
+ const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
189
+ if (hangulWidth !== undefined) {
190
+ width += hangulWidth;
191
+ continue;
192
+ }
193
+
110
194
  // Everything else: EAW of the cluster’s first visible scalar
111
- const codePoint = baseVisible(segment).codePointAt(0);
195
+ const codePoint = visibleSegment.codePointAt(0);
112
196
  width += eastAsianWidth(codePoint, eastAsianWidthOptions);
113
197
 
114
- // Add width for trailing Halfwidth and Fullwidth Forms (e.g., ゙, ゚, ー)
115
- width += trailingHalfwidthWidth(segment, eastAsianWidthOptions);
198
+ // Add width for trailing spacing marks and Halfwidth/Fullwidth Forms (e.g., ゙, ゚, ー)
199
+ width += trailingWidth(visibleSegment, eastAsianWidthOptions);
116
200
  }
117
201
 
118
202
  return width;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depup/string-width",
3
- "version": "8.2.0-depup.0",
3
+ "version": "8.3.0-depup.0",
4
4
  "description": "Get the visual width of a string - the number of columns required to display it (with updated dependencies)",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/string-width",
@@ -62,7 +62,7 @@
62
62
  "east-asian-width"
63
63
  ],
64
64
  "dependencies": {
65
- "get-east-asian-width": "^1.5.0",
65
+ "get-east-asian-width": "^1.7.0",
66
66
  "strip-ansi": "^7.2.0"
67
67
  },
68
68
  "devDependencies": {
@@ -72,15 +72,19 @@
72
72
  },
73
73
  "depup": {
74
74
  "changes": {
75
+ "get-east-asian-width": {
76
+ "from": "^1.5.0",
77
+ "to": "^1.7.0"
78
+ },
75
79
  "strip-ansi": {
76
80
  "from": "^7.1.2",
77
81
  "to": "^7.2.0"
78
82
  }
79
83
  },
80
- "depsUpdated": 1,
84
+ "depsUpdated": 2,
81
85
  "originalPackage": "string-width",
82
- "originalVersion": "8.2.0",
83
- "processedAt": "2026-03-19T03:33:28.284Z",
86
+ "originalVersion": "8.3.0",
87
+ "processedAt": "2026-09-27T01:04:30.506Z",
84
88
  "smokeTest": "passed"
85
89
  }
86
90
  }