diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2021-07-06 15:33:12 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 12:03:12 +0200 |
commit | 2ed222fceb2a2f3f2dfaeff87953e3b599e18641 (patch) | |
tree | ecc56e1e4e08336f958f96e923cc2927ac84e7b0 /extensions/console/01_colors.js | |
parent | ab6b0cefd36f4a2530267c03683e1db1a1b81838 (diff) |
refactor: use primordials for extensions/console (#11249)
Diffstat (limited to 'extensions/console/01_colors.js')
-rw-r--r-- | extensions/console/01_colors.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/extensions/console/01_colors.js b/extensions/console/01_colors.js index d72cd2733..3c7384a6c 100644 --- a/extensions/console/01_colors.js +++ b/extensions/console/01_colors.js @@ -1,8 +1,16 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +/// <reference path="../../core/internal.d.ts" /> + "use strict"; ((window) => { + const { + RegExp, + StringPrototypeReplace, + ArrayPrototypeJoin, + } = window.__bootstrap.primordials; + function code(open, close) { return { open: `\x1b[${open}m`, @@ -12,7 +20,9 @@ } function run(str, code) { - return `${code.open}${str.replace(code.regexp, code.open)}${code.close}`; + return `${code.open}${ + StringPrototypeReplace(str, code.regexp, code.open) + }${code.close}`; } function bold(str) { @@ -57,15 +67,15 @@ // https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js const ANSI_PATTERN = new RegExp( - [ + ArrayPrototypeJoin([ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", - ].join("|"), + ], "|"), "g", ); function stripColor(string) { - return string.replace(ANSI_PATTERN, ""); + return StringPrototypeReplace(string, ANSI_PATTERN, ""); } function maybeColor(fn) { |