Last active
March 11, 2020 14:51
-
-
Save radicaldrew/975c0a621b90c3b28e5141e82e2eaf09 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const removeColors = (string) => { | |
const pattern = [ | |
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', | |
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))' | |
].join('|'); | |
return typeof string === 'string' ? string.replace(new RegExp(pattern, 'g'), '') : string; | |
}; | |
module.exports = removeColors; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment