node-colorify
v2.0.1
Published
Node library to print colored texts in terminal.
Maintainers
Readme
node-colorify
(color & style texts in console)
A node library for printing colored and styled texts in terminal. Uses ANSI color and style codes to format the color and style printed on console. node-colorify is easy to use and supports additional text formatting.
Install
$ npm install node-colorifyRequire as follows:
var color = require('node-colorify');Usage Example
var color = require('node-colorify');
//colorIt - Synchronously
console.log(color.colorItSync('Hello World', {'fColor': 'green'}));
console.log(color.colorItSync('Hello World', {'bColor': 'green', 'fColor': 'red'}));
//colorIt - Asynchronously
color.colorIt('Hello World', {'fColor': 'green'}, function(coloredText) {
console.log(coloredText);
});
color.colorIt('Hello World', {'bColor': 'green', 'fColor': 'red'}, function(coloredText) {
console.log(coloredText);
});
//styleIt - Synchronously
console.log(color.styleItSync('hello', ['bold']));
console.log(color.styleItSync('hello', ['bold', 'blink', 'inverse']));
//styleIt - Asynchronously
color.styleIt('Hello World', ['bold'], function(coloredText) {
console.log(coloredText);
});
color.styleIt('Hello World', ['bold', 'blink', 'inverse'], function(coloredText) {
console.log(coloredText);
});Output

API Documentation
colorIt(text, color, callback) - Asynchronous
This function will return the ANSI formatted string of given color asynchronously.
color
Color format can be specified as follows
bColor - Background Color
fColor - Foreground Color
Foreground alone:
{ 'fColor': 'black'}Background alone:
{ 'bColor': 'red'}Mixed format:
{ 'fColor': 'black', 'bColor': 'red'}Supported list of colors:
1. BLACK (DEFAULT)
2. RED
3. GREEN
4. YELLOW
5. BLUE
6. MAGENTA
7. CYAN
8. WHITEcolorItSync(text, color) - Synchronous
Same as that of colorit functionality, returns the ANSI formatted string of given color synchronously.
styleIt(text, styles, callback) - Asynchronous
This function will return the ANSI formatted string of given style asynchronously.
styles
Style can be specified as follows
Single style
["bold"]Multiple styles
["bold", "blink", "inverse"]Supported list of styles:
1. BOLD
2. LIGHT
3. ULINE (UNDERLINE)
4. BLINK
5. INVERSE
6. HIDEstyleItSync(text, styles) - Synchronous
Same as that of styleIt functionality, returns the ANSI style formatted string of given style synchronously.
