This is a port of the ansi to html converter from bcat to Javascript.
It has a few additions:
toHtml().fg and bg options.<br/> if the newline option is truenpm install ansi-to-html
var Convert = require('ansi-to-html');
var convert = new Convert()
console.log(convert.toHtml('\x1b[30mblack\x1b[37mwhite'));
/*
prints:
<span style="color:#000">black<span style="color:#AAA">white</span></span>
*/