const chalk = require('chalk');
const ansiHtml = require('ansi-html');
const inspect = require('util').inspect;
chalk.enabled = true;
chalk.level = 3;
const c = chalk.hex('#405060')('Hello');
const h = ansiHtml(c);
console.log(inspect(c));
console.log(inspect(h));
Something like this:
'\\u001b[38;2;64;80;96mHello\\u001b[39m'
'<span style="color:#405060;">Hello</span>'
'\\u001b[38;2;64;80;96mHello\\u001b[39m'
'\\u001b[38;2;64;80;96mHello</span>'