color
color
is a library for color conversion and manipulation with support for CSS color strings.
var color = ; color; console; // "hsl(192, 99%, 110%)"
Install
browser
Download the latest color.js. The Color
object is exported.
node
npm install color
And use with var Color = require("color")
API
Setters
var color =
Pass any valid CSS string into Color()
, like "#FFFFFF"
, "#fff"
, "white"
, "hsla(360, 100%, 100%, 0.5)"
var color =
You can also pass a hash of color values into Color()
, keyed on r
or red
for example.
var color =
Load in color values with rgb()
, hsl()
, hsv()
,and cmyk()
. The arguments can also be an array or hash.
Getters
color // {r: 255, g: 255, b: 255}
Get a hash of the rgb values with rgb()
, similarly for hsl()
, hsv()
, and cmyk()
color // [255, 255, 255]
Get an array of the values with rgbArray()
, hslArray()
, hsvArray()
, and cmykArray()
.
color // 255
Get the values for individual channels with alpha
, red
, green
, blue
, hue
, saturation
(hsl), saturationv
(hsv), lightness
, cyan
, magenta
, yellow
, black
color
Also set the value of any channel.
CSS Strings
color // "hsl(320, 50%, 100%)"
Different CSS String formats for the color are on hexString
, rgbString
, percentString
, hslString
, and keyword
(undefined if it's not a keyword color). "rgba"
and "hsla"
are used if the current alpha value of the color isn't 1
.
Manipulation
color // rgb(0, 100, 255) -> rgb(255, 155, 0) color // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%)color // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%) colorcolor // #5CBF54 -> #969696color // #5CBF54 -> #969696 colorcolor color // // chainingcolor
And more to come...