diff --git a/src/ansi-regex.ts b/src/ansi-regex.ts new file mode 100644 index 0000000..b4dbcde --- /dev/null +++ b/src/ansi-regex.ts @@ -0,0 +1,11 @@ +// Embedding this here because the ansi-regex import is +// triggering an jspm error (https://github.com/kubetail-org/fancy-ansi/issues/16) +// https://github.com/chalk/ansi-regex/blob/main/index.js +export default function ansiRegex({onlyFirst = false} = {}) { + const pattern = [ + '[\\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('|'); + + return new RegExp(pattern, onlyFirst ? undefined : 'g'); +}