From 73c3f7e2308ff2707cbe22d5d63400feaff4f506 Mon Sep 17 00:00:00 2001 From: Zelys Date: Sun, 5 Jul 2026 16:39:03 -0500 Subject: [PATCH] Use `stripVTControlCharacters`, require Node.js 22 --- .github/workflows/main.yml | 1 - index.js | 6 +++--- package.json | 5 ++--- test.js | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ab9e0a..622a8a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,6 @@ jobs: node-version: - 24 - 22 - - 20 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/index.js b/index.js index cfc161a..6e61272 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -import stripAnsi from 'strip-ansi'; +import {stripVTControlCharacters} from 'node:util'; import {eastAsianWidth} from 'get-east-asian-width'; /** @@ -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) { diff --git a/package.json b/package.json index 74ccc2d..7df9d99 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ }, "sideEffects": false, "engines": { - "node": ">=20" + "node": ">=22.10" }, "scripts": { "test": "xo && ava && tsd" @@ -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", diff --git a/test.js b/test.js index 0ec22bd..cba23cc 100644 --- a/test.js +++ b/test.js @@ -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);