colorzy
colorzy is a simple tools that adds formatting methods to objects. Most useful with String
, I think.
Changelog
Take a look at the commits/changes on GitHub.
Installation
Install with npm
:
npm install colorzy
Formatting
The returned object by require
offers a method named colorize
that adds formatting
methods to the given object. Please keep in mind that JavaScript has prototype base
derivation so that you have to use the prototype
property of a class to add methods
to all objects of that type.
colorzy; // Add formatting to all Strings
The colorize
method takes two parameters:
- The object
- A
boolean
value: iffalse
(default), methods will only be added if they do not already exists
General
- Bold
- Italic (does not work everywhere)
- Underline
- Inverse
Foreground
- Black
- Blue
- Cyan
- Green
- Grey
- Magenta
- Red
- White
- Yellow
Background
- Black
- Blue
- Cyan
- Green
- Grey
- Magenta
- Red
- White
- Yellow
The methods are named like the formatting option, some has a Background suffix. So, to print red text on green background (please don't do that):
console
Elephant
To print all formatting options to the console, use colorzy.elephant()
.
Example usage
The following example demonstrates the usage of the tool:
var colorzy = ;var util = ; colorzy; console;console;for var i = 0; i < 10; i++ util; for var j = 0; j < 10; j++ var v = i * j; var r = ""+i * j; if r < 10 r = " "+r; if i == j if v < 10 r = r; else r = r; else if v < 10 r = r; else r = r; util; util;
More information
There is a blog post about colorzy including screenshots and a notice concerning WebStorm.