Skip to content

Commit 68d50e5

Browse files
authored
Replace strip-ansi with native stripVTControlCharacters (#249)
1 parent 20d4bdb commit 68d50e5

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import process from 'node:process';
2+
import {stripVTControlCharacters} from 'node:util';
23
import chalk from 'chalk';
34
import cliCursor from 'cli-cursor';
45
import cliSpinners from 'cli-spinners';
56
import logSymbols from 'log-symbols';
6-
import stripAnsi from 'strip-ansi';
77
import stringWidth from 'string-width';
88
import isInteractive from 'is-interactive';
99
import isUnicodeSupported from 'is-unicode-supported';
@@ -186,7 +186,7 @@ class Ora {
186186

187187
#computeLineCountFrom(text, columns) {
188188
let count = 0;
189-
for (const line of stripAnsi(text).split('\n')) {
189+
for (const line of stripVTControlCharacters(text).split('\n')) {
190190
count += Math.max(1, Math.ceil(stringWidth(line) / columns));
191191
}
192192

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
"is-unicode-supported": "^2.1.0",
5151
"log-symbols": "^7.0.1",
5252
"stdin-discarder": "^0.2.2",
53-
"string-width": "^8.1.0",
54-
"strip-ansi": "^7.1.2"
53+
"string-width": "^8.1.0"
5554
},
5655
"devDependencies": {
5756
"@types/node": "^24.5.0",

test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import process from 'node:process';
22
import {PassThrough as PassThroughStream} from 'node:stream';
3+
import {stripVTControlCharacters} from 'node:util';
34
import assert from 'node:assert/strict';
45
import test from 'node:test';
56
import getStream from 'get-stream';
6-
import stripAnsi from 'strip-ansi';
77
import TransformTTY from 'transform-tty';
88
import ora, {oraPromise, spinners} from './index.js';
99

@@ -35,7 +35,7 @@ const doSpinner = async (function_, extraOptions = {}) => {
3535
function_(spinner);
3636
stream.end();
3737

38-
return stripAnsi(await output);
38+
return stripVTControlCharacters(await output);
3939
};
4040

4141
test('main', async () => {
@@ -186,7 +186,7 @@ test('oraPromise() - resolves', async () => {
186186
await resolves;
187187
stream.end();
188188

189-
assert.match(stripAnsi(await output), /[] foo\n$/);
189+
assert.match(stripVTControlCharacters(await output), /[] foo\n$/);
190190
});
191191

192192
test('oraPromise() - rejects', async () => {
@@ -205,7 +205,7 @@ test('oraPromise() - rejects', async () => {
205205

206206
stream.end();
207207

208-
assert.match(stripAnsi(await output), /[×] foo\n$/);
208+
assert.match(stripVTControlCharacters(await output), /[×] foo\n$/);
209209
});
210210

211211
test('erases wrapped lines', () => {
@@ -322,7 +322,7 @@ test('reset frameIndex when setting new spinner', async () => {
322322
stream.end();
323323

324324
assert.strictEqual(spinner._frameIndex, 0);
325-
assert.match(stripAnsi(await output), /foo baz/);
325+
assert.match(stripVTControlCharacters(await output), /foo baz/);
326326
});
327327

328328
test('set the correct interval when changing spinner (object case)', () => {
@@ -590,7 +590,7 @@ test('oraPromise(function) passes spinner and supports successText function', as
590590
});
591591

592592
stream.end();
593-
assert.match(stripAnsi(await output), /[] done: 7\n$/);
593+
assert.match(stripVTControlCharacters(await output), /[] done: 7\n$/);
594594
});
595595

596596
test('oraPromise(function) rejects and supports failText function', async () => {
@@ -611,7 +611,7 @@ test('oraPromise(function) rejects and supports failText function', async () =>
611611
} catch {}
612612

613613
stream.end();
614-
assert.match(stripAnsi(await output), /[×] oops: boom\n$/);
614+
assert.match(stripVTControlCharacters(await output), /[×] oops: boom\n$/);
615615
});
616616

617617
test('oraPromise() validates `action` type', async () => {
@@ -710,7 +710,7 @@ test('start() with empty text and isEnabled:false produces no output', async ()
710710
spinner.start();
711711
stream.end();
712712

713-
const text = stripAnsi(await output);
713+
const text = stripVTControlCharacters(await output);
714714
assert.match(text, /^(?![\s\S])/);
715715
});
716716

@@ -1495,7 +1495,7 @@ test('disabled spinner preserves prefix/suffix/indent', async () => {
14951495
spinner.start();
14961496
stream.end();
14971497

1498-
const text = stripAnsi(await output);
1498+
const text = stripVTControlCharacters(await output);
14991499
assert.strictEqual(text, ' pre - test post\n');
15001500
});
15011501

0 commit comments

Comments
 (0)