Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
node-version:
- 24
- 22
- 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import stripAnsi from 'strip-ansi';
import {stripVTControlCharacters} from 'node:util';
import {eastAsianWidth} from 'get-east-asian-width';

/**
Expand Down Expand Up @@ -155,9 +155,9 @@ export default function stringWidth(input, options = {}) {

let string = input;

// Avoid calling stripAnsi when there are no ANSI escape sequences (ESC = 0x1B, CSI = 0x9B)
// Avoid calling stripVTControlCharacters when there are no ANSI escape sequences (ESC = 0x1B, CSI = 0x9B)
if (!countAnsiEscapeCodes && (string.includes('\u001B') || string.includes('\u009B'))) {
string = stripAnsi(string);
string = stripVTControlCharacters(string);
}

if (string.length === 0) {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"sideEffects": false,
"engines": {
"node": ">=20"
"node": ">=22.10"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -54,8 +54,7 @@
"east-asian-width"
],
"dependencies": {
"get-east-asian-width": "^1.5.0",
"strip-ansi": "^7.1.2"
"get-east-asian-width": "^1.5.0"
},
"devDependencies": {
"ava": "^6.4.1",
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,6 @@ test('ambiguous in text (wide)', macro, '±×÷', 6, {ambiguousIsNarrow: false})
test('ambiguous mixed with CJK', macro, '±你', 3);
test('ambiguous mixed with CJK (wide)', macro, '±你', 4, {ambiguousIsNarrow: false});

// `stripAnsi` guard: non-ANSI strings should not call `stripAnsi`
// `stripVTControlCharacters` guard: non-ANSI strings should not trigger stripping
test('non-ASCII without ANSI escapes', macro, '你好世界', 8);
test('Latin1 without ANSI escapes', macro, 'résumé', 6);
Loading