@depup/string-width 8.2.0-depup.0 → 8.2.2-depup.7

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.2.2 |
17
+ | Processed | 2026-07-26 |
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.6.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.6.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-07-26T01:04:10.230Z",
13
+ "totalUpdated": 2
10
14
  }
package/index.js CHANGED
@@ -5,19 +5,22 @@ 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
18
  // Whole-cluster zero-width
17
- const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Mark}|\p{Surrogate})+$/v;
19
+ const zeroWidthClusterRegex = /^(?:\p{Default_Ignorable_Code_Point}|\p{Control}|\p{Format}|\p{Nonspacing_Mark}|\p{Enclosing_Mark}|\p{Surrogate})+$/v;
18
20
 
19
21
  // 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;
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;
21
24
 
22
25
  // RGI emoji sequences
23
26
  const rgiEmojiRegex = /^\p{RGI_Emoji}$/v;
@@ -53,13 +56,91 @@ function isZeroWidthCluster(segment) {
53
56
  return zeroWidthClusterRegex.test(segment);
54
57
  }
55
58
 
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);
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);
62
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);
63
144
  }
64
145
  }
65
146
 
@@ -107,12 +188,19 @@ export default function stringWidth(input, options = {}) {
107
188
  continue;
108
189
  }
109
190
 
191
+ const visibleSegment = baseVisible(segment);
192
+ const hangulWidth = hangulClusterWidth(visibleSegment, eastAsianWidthOptions);
193
+ if (hangulWidth !== undefined) {
194
+ width += hangulWidth;
195
+ continue;
196
+ }
197
+
110
198
  // Everything else: EAW of the cluster’s first visible scalar
111
- const codePoint = baseVisible(segment).codePointAt(0);
199
+ const codePoint = visibleSegment.codePointAt(0);
112
200
  width += eastAsianWidth(codePoint, eastAsianWidthOptions);
113
201
 
114
- // Add width for trailing Halfwidth and Fullwidth Forms (e.g., ゙, ゚, ー)
115
- width += trailingHalfwidthWidth(segment, eastAsianWidthOptions);
202
+ // Add width for trailing spacing marks and Halfwidth/Fullwidth Forms (e.g., ゙, ゚, ー)
203
+ width += trailingWidth(visibleSegment, eastAsianWidthOptions);
116
204
  }
117
205
 
118
206
  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.2.2-depup.7",
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.6.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.6.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.2.2",
87
+ "processedAt": "2026-07-26T01:04:17.698Z",
84
88
  "smokeTest": "passed"
85
89
  }
86
90
  }