UNPKG

692 BJavaScriptView Raw
1var 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
12function stripAnsi(string) {
13 if (typeof string !== "string") {
14 throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
15 }
16
17 return string.replace(ansiRegex, "");
18}
19
20export default stripAnsi;
\No newline at end of file