@chriscodesthings/compress-css-hex-color
v1.1.2
Published
Convert a CSS hex color code to short form
Downloads
256
Maintainers
Readme
compress-css-hex-color ·
Convert a CSS hex color code to short form
Description
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
See...
Install
npm install --save @chriscodesthings/compress-css-hex-color
Use
import compressCSSHexColor from '@chriscodesthings/compress-css-hex-color';
console.log(compressCSSHexColor("#ff0000dd"));
// => #f00d
Types
This package uses types from:
Syntax
compressCSSHexColor(color);
Parameters
- color: a CSS hex color string
Return Value
Returns the short form of the CSS color code, or the original string if it can't be compressed.