Colorize terminal text for Node
Returns a colorizer function.
Both foreground & background arguments expect a color. A color could be one of the following:
- A supported color name (see list below)
- 0-255 Number - see 256 color palette
- HEX - a hex color string that starts with a hash sign (e.g.
'#1d3ddf'
) - RGB - an array of three values (e.g.
[200, 40, 40]
)
Example:
// my-app.js
const createColor = require('my-colors');
const warning = createColor('yellow', 'red', 'bold');
const msg = warning('Attention: Do not do that.');
console.log(msg)
- Black
- Red
- Green
- Yellow
- Blue
- Magenta
- Cyan
- White
Note: Support may vary between different OS/terminals
- bold
- dim
- italic
- underline
- invert
- strike
Example:
// using hex color foreground, RGB background, and bold & underline modifiers
createColor('#000000', [77, 160, 255], ['bold', 'underline']);