Skip to content

Commit 51aa68d

Browse files
authored
Require Node.js 16 and improve length calculation (#17)
1 parent a1cdfe8 commit 51aa68d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13+
- 18
1314
- 16
1415
steps:
15-
- uses: actions/checkout@v2
16-
- uses: actions/setup-node@v2
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v3
1718
with:
1819
node-version: ${{ matrix.node-version }}
1920
- run: npm install

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import stripAnsi from 'strip-ansi';
2-
import charRegex from 'char-regex';
2+
3+
const segmenter = new Intl.Segmenter();
34

45
export default function stringLength(string, {countAnsiEscapeCodes = false} = {}) {
56
if (string === '') {
@@ -14,5 +15,11 @@ export default function stringLength(string, {countAnsiEscapeCodes = false} = {}
1415
return 0;
1516
}
1617

17-
return string.match(charRegex()).length;
18+
let length = 0;
19+
20+
for (const _ of segmenter.segment(string)) { // eslint-disable-line no-unused-vars
21+
length++;
22+
}
23+
24+
return length;
1825
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "https://sindresorhus.com"
1212
},
1313
"engines": {
14-
"node": ">=12.20"
14+
"node": ">=16"
1515
},
1616
"type": "module",
1717
"exports": "./index.js",
@@ -37,7 +37,6 @@
3737
"codes"
3838
],
3939
"dependencies": {
40-
"char-regex": "^2.0.0",
4140
"strip-ansi": "^7.0.1"
4241
},
4342
"devDependencies": {

0 commit comments

Comments
 (0)