A utility that returns hex/rgb/hsl properties of a color
npm install color-props --save
var colorProps = require('color-props');
var color = colorProps('#abcdef');
// returned color object
{
hex: '#abcdef',
rgb: [ 171, 205, 239 ],
rgbCss: 'rgb(171, 205, 239)',
hsl: [ 210, '68%', '80%' ],
hslCss: 'hsl(210, 68%, 80%)',
r: 171,
g: 205,
b: 239,
a: null,
h: 210,
s: '68%',
l: '80%',
H: 210,
S: 0.6800000000000003,
L: 0.803921568627451
}
color-props supports the following for inputs:
Hexadecimal
var color = colorProps('#abcdef');
Shorthand Hex
var color = colorProps('#abc');
rgb
var color = colorProps('rgb(123, 45, 67)'); // or
var color = colorProps('123, 45, 67');
rgba
var color = colorProps('rgba(123, 45, 67, .25)'); // or
var color = colorProps('123, 45, 67, .25');
The difference in the h/s/l and H/S/L properties in the color object is that the ones in caps are the raw numbers from the calculations.
- Add HSL input