-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Remove dependency on strip-ansi and embed the tiny function…
… instead (#2499 by @jamonholmgren) [skip ci] * Remove dependency on strip-ansi and embed the tiny function instead * Reset yarn.lock back to where it was before * Reset Podfile
- Loading branch information
1 parent
3e86d93
commit b7c2453
Showing
4 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js | ||
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") | ||
} | ||
|
||
export function stripANSI(string) { | ||
if (typeof string !== "string") { | ||
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``) | ||
} | ||
|
||
// Even though the regex is global, we don't need to reset the `.lastIndex` | ||
// because unlike `.exec()` and `.test()`, `.replace()` does it automatically | ||
// and doing it manually has a performance penalty. | ||
return string.replace(ansiRegex(), "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters