summaryrefslogtreecommitdiff
path: root/cli/js/colors.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2020-04-11 07:08:11 +0100
committerGitHub <noreply@github.com>2020-04-11 02:08:11 -0400
commit2b362bef8523f3d8c05ce5d3d4b4a839b669568d (patch)
treedd5c567e66fc3141fa486c93ce2e899aba802fe4 /cli/js/colors.ts
parent2feb661b858f3c8380ceb0362d137079e12b9248 (diff)
refactor(cli/fmt_errors): Format stack frames in prepareStackTrace() (#4706)
Diffstat (limited to 'cli/js/colors.ts')
-rw-r--r--cli/js/colors.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/cli/js/colors.ts b/cli/js/colors.ts
index d0ecdd139..9b5e7be4e 100644
--- a/cli/js/colors.ts
+++ b/cli/js/colors.ts
@@ -62,3 +62,16 @@ export function white(str: string): string {
export function gray(str: string): string {
return run(str, code(90, 39));
}
+
+// https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js
+const ANSI_PATTERN = new RegExp(
+ [
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
+ ].join("|"),
+ "g"
+);
+
+export function stripColor(string: string): string {
+ return string.replace(ANSI_PATTERN, "");
+}