mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 12:58:54 -05:00
refactor: use primordials for extensions/console (#11249)
This commit is contained in:
parent
ab6b0cefd3
commit
2ed222fceb
2 changed files with 380 additions and 185 deletions
|
@ -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) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue