I have some scripts for which installing dependencies / node_modules would be overkill, but I still could use some colors for the terminal. Right now, I think in userland it's standard to install colors/chalk in node_modules but I am wondering if there is a way to do so with just Node.js core?
Seems like it would be handy for scripts and wouldn't add too much to core? dunno
i don't think core needs to expose this, it's quite simple to do even without a library:
const colors = {
'bold': [1, 22],
'italic': [3, 23],
'underline': [4, 24],
'inverse': [7, 27],
'white': [37, 39],
'grey': [90, 39],
'black': [30, 39],
'blue': [34, 39],
'cyan': [36, 39],
'green': [32, 39],
'magenta': [35, 39],
'red': [31, 39],
'yellow': [33, 39]
};
function stylize(color, str) {
const [start, end] = colors[color];
return `\u001b[${start}m${str}\u001b[${end}m`;
}
I agree, this isn't something that needs to explicitly live in or be exposed in core.
Closing this, as @devsnek pointed out a solution that doesn't involve adding things to core any more than what's absolutely necessary. Also, popular solutions exist in the userland. Feel free to reopen this if you feel otherwise.
Most helpful comment
i don't think core needs to expose this, it's quite simple to do even without a library: