colorider

1.2.0 • Public • Published
Colorider

Colorider Module

A node.js module for output styling in Terminal, iTerm, etc.

Install

˃₋ npm install colorider

Usage

const Cr = require('colorider');
console.log(Cr.red.bold('Hi colorider!'));

Hi colorider!

console.log(Cr.cyan('Text') === '\u001B[36mText\u001B[39m');

true


Tags preset

The following tags works with most terminals and terminals emulators.


Modifier tags (text formatting)

bolddimitalicunderlineblinkinversehiddenstrike


Color scheme tags

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

Converter tags

The special tags for color models conversion to ansi code.

Foreground Background
rgb RGB
hex HEX

Example

// 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'));

Modifiers tags


Conversion level

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'));

Background tags

comparing level


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)



Base features

Style combining

console.log(Cr.red('Red') + ' Normal ' + Cr.blue('Blue'));

Style combining

Chain tags

console.log(Cr.white.bold.underline('White bold underline'));

Chaining tags

Style definition

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'));

Style definition

Nested tags

// 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');

Nested tags


Package Sidebar

Install

npm i colorider

Weekly Downloads

10

Version

1.2.0

License

MIT

Unpacked Size

185 kB

Total Files

18

Last publish

Collaborators

  • alexkulagin