Parse ANSI colors and styles
npm install ansi-style-parser
var c = require('chalk');
var parser = require('ansi-style-parser');
var txt = 'Some ';
txt += c.bold.green('styled ' + c.underline.bgBlack('text') + c.red('!'));
console.log(parser(txt));
Output:
[ { styles: [],
text: 'Some ' },
{ styles: [ 'bold', 'green' ],
text: 'styled ' },
{ styles: [ 'bold', 'green', 'underline', 'bgBlack' ],
text: 'text' },
{ styles: [ 'bold', 'red' ],
text: '!' } ]
MIT