ansicolors
Functions that surround a string with ansicolor codes so it prints in color.
In case you need styles, like bold
, have a look at ansistyles.
Installation
npm install ansicolors
Usage
var colors = ; // foreground colorsvar redHerring = colors;var blueMoon = colors;var brighBlueMoon = colors; console; // this will print 'herring' in redconsole; // this 'moon' in blueconsole; // I think you got the idea // background colorsconsole;console; // mixing background and foreground colors// below two lines have same result (order in which bg and fg are combined doesn't matter)console;console;
Advanced API
ansicolors allows you to access opening and closing escape sequences separately.
var colors = ; { return ;} console;console; // => open blue '\u001b[34m'// close bgBlack '\u001b[49m'
Tests
Look at the tests to see more examples and/or run them via:
npm explore ansicolors && npm test
Alternatives
ansicolors tries to meet simple use cases with a very simple API. However, if you need a more powerful ansi formatting tool, I'd suggest to look at the features of the ansi module.