diff --git a/colors.js b/colors.js index e3f9009..1eb96f6 100644 --- a/colors.js +++ b/colors.js @@ -222,3 +222,7 @@ function zalgo(text, options) { }; return heComes(text); } + +addProperty('stripColors', function() { + return ("" + this).replace(/\u001b\[\d+m/g,''); +}); diff --git a/example.js b/example.js index 184a741..6c8910c 100644 --- a/example.js +++ b/example.js @@ -3,13 +3,16 @@ var colors = require('./colors'); //colors.mode = "browser"; +var test = colors.red("hopefully colorless output"); sys.puts('Rainbows are fun!'.rainbow); sys.puts('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported sys.puts('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported //sys.puts('zalgo time!'.zalgo); +sys.puts(test.stripColors); sys.puts(colors.rainbow('Rainbows are fun!')); sys.puts(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported sys.puts(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported //sys.puts(colors.zalgo('zalgo time!')); +sys.puts(colors.stripColors(test));