stripAnsi.js 692 B

1234567891011121314151617181920
  1. var ansiRegex = new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|"), "g");
  2. /**
  3. *
  4. * Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
  5. * Adapted from code originally released by Sindre Sorhus
  6. * Licensed the MIT License
  7. *
  8. * @param {string} string
  9. * @return {string}
  10. */
  11. function stripAnsi(string) {
  12. if (typeof string !== "string") {
  13. throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
  14. }
  15. return string.replace(ansiRegex, "");
  16. }
  17. export default stripAnsi;