chartjs-color
JavaScript library for color conversion and manipulation with support for CSS color strings.
var color = ; color; console; // "hsla(262, 59%, 81%, 0.5)"
Install
$ npm install color
Usage
var Color =
Setters
var color = var color = var color = var color =
Pass any valid CSS color string into Color()
or a hash of values. Also load in color values with rgb()
, hsl()
, hsv()
, hwb()
, and cmyk()
.
color
Set the values for individual channels with alpha
, red
, green
, blue
, hue
, saturation
(hsl), saturationv
(hsv), lightness
, whiteness
, blackness
, cyan
, magenta
, yellow
, black
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 value for an individual channel.
CSS Strings
color // "hsl(320, 50%, 100%)"
Different CSS String formats for the color are on hexString
, rgbString
, percentString
, hslString
, hwbString
, 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
.
Luminosity
color; // 0.412
The WCAG luminosity of the color. 0 is black, 1 is white.
color // 12
The WCAG contrast ratio to another color, from 1 (same color) to 21 (contrast b/w white and black).
color; // truecolor; // false
Get whether the color is "light" or "dark", useful for deciding text color.
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%) color // hsl(100, 50%, 50%) -> hsl(100, 75%, 50%)color // hsl(100, 50%, 50%) -> hsl(100, 25%, 50%)color // #5CBF54 -> #969696 color // hwb(100, 50%, 50%) -> hwb(100, 75%, 50%)color // hwb(100, 50%, 50%) -> hwb(100, 50%, 75%) color // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 0.4)color // rgba(10, 10, 10, 0.8) -> rgba(10, 10, 10, 1.0) color // hsl(60, 20%, 20%) -> hsl(240, 20%, 20%)color // hsl(60, 20%, 20%) -> hsl(330, 20%, 20%) color // cyan -> rgb(128, 255, 128)color // cyan -> rgb(77, 255, 179) // chainingcolor
Clone
You can can create a copy of an existing color object using clone()
:
color // -> New color object
And more to come...
Propers
The API was inspired by color-js. Manipulation functions by CSS tools like Sass, LESS, and Stylus.