UNPKG

smashup

Version:

Just some code :)

53 lines (48 loc) 1.51 kB
/** * Logs a message beautifully, no questions asked! * @type {Function} * @param {*} message Message to log. * @param {String} bg Message background. * @param {String} color Message text color. * @returns {void} Returns undefined. */ const log = (message, background, textColor) => { let bg = '', color = ''; if (background) { background = background.toLowerCase(); switch (background) { case 'black': bg += '\x1b[40m'; break; case 'red': bg += '\x1b[41m'; break; case 'green': bg += '\x1b[42m'; break; case 'yellow': bg += '\x1b[43m'; break; case 'blue': bg += '\x1b[44m'; break; case 'magenta': bg += '\x1b[45m'; break; case 'cyan': bg += '\x1b[46m'; break; case 'white': bg += '\x1b[47m'; break; } } if (textColor) { textColor = textColor.toLowerCase(); switch (textColor) { case 'black': color += '\x1b[30m'; break; case 'red': color += '\x1b[31m'; break; case 'green': color += '\x1b[32m'; break; case 'yellow': color += '\x1b[33m'; break; case 'blue': color += '\x1b[34m'; break; case 'magenta': color += '\x1b[35m'; break; case 'cyan': color += '\x1b[36m'; break; case 'white': color += '\x1b[37m'; break; } } if (bg) { message = ` ${message} `; } if (color || bg) { console.log(`${color}${bg}%s\x1b[0m`, message); } else { console.log(message); } }; module.exports = { log }