Expands a CSS hex color to it's longest form
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
npm install --save @chriscodesthings/expand-css-hex-color
import expandCSSHexColor from '@chriscodesthings/expand-css-hex-color';
console.log(expandCSSHexColor("#cafe"));
// => #ccaaffee
This package uses types from:
expandCSSHexColor(color);
- color: a CSS hex color string
Returns the longest form of the CSS color code.
// 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
}