Hop aboard the rainbow. Have some colors. I found all existing libs out there either not adequate for my needs and usually lacking most of the tools I wanted.
The api is designed to be very easy to use. The base exports is the Rainbow function which attempts to determine from given inputs what type of color you're providing. All colors are translated to xterm-256 colors internally first. The returned value is a function that can then be called on text to escape it. In this way the Ansi function objects act as both storage for settings and as text transformers.
var R = ;//red background, white foreground, underlined, with one space padding on either sidevar red = ;//now red can be used on text to escape itconsole;
closest(n): return the
n closest colors using HSL to measure.
gradient(c,n): returns an array of
n length with colors interpolating to
c using HSL to measure.
basic(bg): convert to the nearest of the basic 16 colors for downgrading. Set
bg to true to get the bg escape
style(): Set multiple other styles at once, like italic, etc.
child(): Return a new function that inherits from this one so it can be customized
fg(): Specify another color as the foreground for this. Causes this color to become the bg.
bg(): Specify another color as the background, making this the foreground. /* bg and fg are mutually exclusive */
ital(): Toggles this
inv(): Toggles this
under(): Toggles this
pad(n): Pads text when escaped to
n. If no
n is provided then it will cycle from 0 to 4 and back eac .pad().
rgb(): return an rgb array for the color
hsl(): return an hsl array for the color
ansi(): return the ansi code for the color
hex(): return the HTML hex code for the color
The return type for operations that return sets is
ColorSet. A ColorSet is just an array with a bit of extra functionality. All the Array functions that return new arrays are wrapped so that you always get back a ColorSet. This allows you to do multiple filters and mappings and still have a ColorSet.
The following properties do the same as the single item one, except to every item in the set.
hsl, rgb, ansi, fg, bg, ital, inv, under, pad
The following are wrapped version of the Array.prototype function, but always returning a ColorSet instead of an Array map, sort, concat, slice