summaryrefslogtreecommitdiff
path: root/std/fmt/colors.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/fmt/colors.ts')
-rw-r--r--std/fmt/colors.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/std/fmt/colors.ts b/std/fmt/colors.ts
index 64b4458fc..832f3b164 100644
--- a/std/fmt/colors.ts
+++ b/std/fmt/colors.ts
@@ -205,3 +205,16 @@ export function bgRgb24(str: string, color: Rgb): string {
)
);
}
+
+// 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, "");
+}