Convert a CSS hex color code to short form
Compresses a CSS hex color code.
If the string passed is already a short form color code or it is a long form color code that cannot be shortened, the color is returned unmodified.
If a long form color code is passed and can be shortened, the short form of the color is returned.
If the alpha value is F or FF then it is removed.
Example hex color codes:
#000 // black short form
#000000 // black long form
#663399 // rebeccapurple
#66449988 // ... with 53% transparency
#6498 // ... in short form
npm install --save @chriscodesthings/compress-css-hex-color
import compressCSSHexColor from '@chriscodesthings/compress-css-hex-color';
console.log(compressCSSHexColor("#ff0000dd"));
// => #f00d
This package uses types from:
compressCSSHexColor(color);
- color: a CSS hex color string
Returns the short form of the CSS color code, or the original string if it can't be compressed.
- is-css-hex-color: Determine if a string is a hex color code
- random-css-hex-color: Generates a random color in CSS hex format
- rgba-color-to-css-hex: Converts an RGB or RGBA color to a CSS hex color code
- color-object: Simple, lightweight class to store and manipulate a color, and convert between formats