A node.js module for output styling in Terminal, iTerm, etc.
˃₋ npm install colorider
const Cr = require('colorider');
console.log(Cr.red.bold('Hi colorider!'));
console.log(Cr.cyan('Text') === '\u001B[36mText\u001B[39m');
The following tags works with most terminals and terminals emulators.
bold
dim
italic
underline
blink
inverse
hidden
strike
Foreground (text) | Background | ||
---|---|---|---|
normal | bright | normal | bright |
black |
gray |
BLACK |
GRAY |
red |
red2 |
RED |
RED2 |
green |
green2 |
GREEN |
GREEN2 |
yellow |
yellow2 |
YELLOW |
YELLOW2 |
blue |
blue2 |
BLUE |
BLUE2 |
magenta |
magenta2 |
MAGENTA |
MAGENTA2 |
cyan |
cyan2 |
CYAN |
CYAN2 |
light |
white |
LIGHT |
WHITE |
The special tags for color models conversion to ansi code.
Foreground | Background |
---|---|
rgb |
RGB |
hex |
HEX |
// formatting text
console.log(Cr.bold('Bold modifier'));
console.log(Cr.italic('Italic modifier'));
console.log(Cr.underline('Underline modifier'));
// foreground (text color)
console.log(Cr.red('Red color'));
console.log(Cr.rgb(255, 224, 0)('Yellow color'));
console.log(Cr.hex('#00D75F')('Green color'));
// background
console.log(Cr.BLACK('Black background'));
console.log(Cr.RGB(255, 224, 0)('Yellow background'));
console.log(Cr.HEX('#EEEEEE')('White background'));
console.log('level:', Cr.level); // default 2
Cr.level = 1;
console.log(Cr.RGB(255, 250, 154)('Conversion level 1'));
Cr.level = 2;
console.log(Cr.RGB(255, 250, 154)('Conversion level 2'));
Cr.level = 3;
console.log(Cr.RGB(255, 250, 154)('Conversion level 3'));
Levels | |
---|---|
0 |
disable conversion |
1 |
16 colors (4-bit the terminal color scheme) |
2 |
256 colors (8-bit default) |
3 |
16 777 216 color variations (24-bit True color) |
console.log(Cr.red('Red') + ' Normal ' + Cr.blue('Blue'));
console.log(Cr.white.bold.underline('White bold underline'));
const strBold = Cr.bold;
const strRed = strBold.red;
const strWhiteBg = strRed.HEX('#FFFFFF');
console.log(Cr('Normal'));
console.log(strBold('Bold'));
console.log(strRed('Bold Red'));
console.log(strRed('Bold Red White background'));
// string
console.log('before', Cr.red('( a', Cr.yellow('( b', Cr.green('( c )'), 'b )'), 'a )'), 'after');
// difine
const strRed = Cr.red('( c )');
const strYellow = Cr.yellow('( b', strRed, 'b )');
const strGreen = Cr.green('( a', strYellow, 'a )');
console.log('before', strGreen, 'after');