Skip to content

Instantly share code, notes, and snippets.

@radicaldrew
Last active March 11, 2020 14:51
Show Gist options
  • Save radicaldrew/975c0a621b90c3b28e5141e82e2eaf09 to your computer and use it in GitHub Desktop.
Save radicaldrew/975c0a621b90c3b28e5141e82e2eaf09 to your computer and use it in GitHub Desktop.
'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