index.js 468 B

1234567891011121314
  1. import ansiRegex from 'ansi-regex';
  2. const regex = ansiRegex();
  3. export default function stripAnsi(string) {
  4. if (typeof string !== 'string') {
  5. throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
  6. }
  7. // Even though the regex is global, we don't need to reset the `.lastIndex`
  8. // because unlike `.exec()` and `.test()`, `.replace()` does it automatically
  9. // and doing it manually has a performance penalty.
  10. return string.replace(regex, '');
  11. }