We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2b8c961 commit 840a5eaCopy full SHA for 840a5ea
index.js
@@ -1,9 +1,14 @@
1
import ansiRegex from 'ansi-regex';
2
3
+const regex = ansiRegex();
4
+
5
export default function stripAnsi(string) {
6
if (typeof string !== 'string') {
7
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
8
}
9
- return string.replace(ansiRegex(), '');
10
+ // Even though the regex is global, we don't need to reset the `.lastIndex`
11
+ // because unlike `.exec()` and `.test()`, `.replace()` does it automatically
12
+ // and doing it manually has a performance penalty.
13
+ return string.replace(regex, '');
14
0 commit comments