A lib for easily translating and manipulating colors and sets of colors centered around xterm-256 pallette
Want to see pretty graphs? Log in now!
npm install repl-rainbow
|10||downloads in the last month|
|Last Published By|
|Version||0.1.1 last updated 2 years ago|
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.
- provide easy translating between core color spaces of RGB and HSL and 256 color Ansi
- translate from any one to any other with ease and terse syntax
- provide baseline tools for generating sets of colors like gradients and nearest colors
- transform arrays of colors at at a single time
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 want.
var rainbow = require('repl-rainbow'); // explicit rainbow('hsl', 180, 1, 0.5); // guessing from numbers rainbow(255,0,0); //rgb rainbow(50) //ansi // arrays work rainbow([255,0,0]);
Aside from the main function there's also a direct function for each. They all have identical methods. RGB has an rgb method that returns itself, for example, for the sake of consistency.
The differences are:
- rainbow.RGB has
- rainbow.HSL has
- rainbow.Ansi has
The common api is:
- rgb(): return an rgb instance for the color
- hsl(): return an hsl instance for the color
- ansi(): return an ansi instance for the color
- hex(): return the HTML hex code for the color as rgb
- closest(n): return the n closest colors, using that color space's rules
- gradient(c,n): returns an array of
nlength with colors interpolating to
cin that color space
A few bonus extras are avaiable on Ansi types
- basic(bg): convert to the nearest of the basic 16 colors for downgradging. Set
bgto true to get the bg escape
- escape(text, type): escapes the text with the full ansi escape sequence for the color. Set
bgto true for the bg escape
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.
- hsl(): maps the ColorSet to another ColorSet where all the values have been converted to hsl's
- rgb(): same for rgb
- ansi(): same for ansi