UNPKG

barecolor

Version:

A tiny JavaScript utility for printing colorful console messages

19 lines (12 loc) 462 B
const colors = { black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, gray: 90 }, supported = /color|ansi|cygwin|linux/i.test(process.env.TERM) for (let name in colors ) { const color = colors[name] const fn = module.exports[name] = function(msg) { if (supported) msg = `\u001b[${color}m${msg}\u001b[39m` process.stdout.write(msg) } module.exports[name + 'ln'] = function(str) { fn(str + '\n') } }