A cored, fixed, documented and optimized version of the popular colors.js. Can be used as a drop-in replacement, also works correctly in the browser, provides a CSS mode and has been compiled through Closure Compiler using advanced optimizations. Additionally, nearly every issue and pull request on the original has been incorporated.
npm install colour
This package extends the global String prototype with additional getters that apply terminal colors to your texts. Available styles are:
- Emphasis: bold, italic, underline, inverse
- Colors: yellow, cyan, white, magenta, green, red, grey, blue
- Sequencers: rainbow, zebra, random
var colour = ;console; // outputs green textconsole // outputs red underlined textconsole; // inverses the colorconsole; // rainbow (ignores spaces)
Or: As a drop-in replacement for
var /* just name it */ colors = ;...
Its also possible to define your own themes by creating new getters on the String object. Example:
var colour = ;colour;console; // outputs bold red textconsole; // outputs underlined yellow textconsole; // Alternatively
Console, browser and browser-css mode
var colour = ;...colourmode = 'none'; // No colors at allcolourmode = 'console'; // Adds terminal colors (default on node.js)colourmode = 'browser'; // Adds HTML colors (default in browsers)colourmode = 'browser-css'; // Adds special CSS (see examples/example.css)
Uninstalling / reinstalling on the global scope
If you have a reason to use a fresh String prototype in your application, you may also revert all extensions made.
var colour = ;...colour; // Removes all custom properties from the String prototype...colour; // Re-installs them...
- node.js/CommonJS compatible
- RequireJS/AMD compatible
- Browser/shim compatible
- Closure Compiler externs included
- Zero dependencies
Based on work started by Marak (Marak Squires), cloudhead (Alexis Sellier), mmalecki (Maciej Małecki), nicoreed (Nico Reed), morganrallen (Morgan Allen), JustinCampbell (Justin Campbell) and ded (Dustin Diaz).
The MIT-License (MIT)