@chriscodesthings/expand-css-hex-color
v1.1.1
Published
Expands a CSS hex color to it's longest form
Downloads
8
Readme
expand-css-hex-color ·
Expands a CSS hex color to it's longest form
Description
Expands a CSS hex colour code. If the string passed is already a long form colour code then it is unmodified. If a short form colour code is passed, the longest form of the colour is returned.
Alpha ff will be added if no alpha is present in the colour code.
Example hex color codes:
#000 // black short form
#000000 // black long form
#663399 // rebeccapurple
#66339988 // ... with 53% transparency
#6498 // ... in short form
#FF0000FF // solid red with alpha
See...
Install
npm install --save @chriscodesthings/expand-css-hex-color
Use
import expandCSSHexColor from '@chriscodesthings/expand-css-hex-color';
console.log(expandCSSHexColor("#cafe"));
// => #ccaaffee
Types
This package uses types from:
Syntax
expandCSSHexColor(color);
Parameters
- color: a CSS hex color string
Return Value
Returns the longest form of the CSS color code.
Examples
// convert from CSS to RGB
function cssToRGB(col) {
// ensure correct input length
col = expandCSSHexColor(col);
// col will now definitely be formatted as #aabbccdd
// convert to RGB
}