@chriscodesthings/compress-css-hex-color
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

compress-css-hex-color · Test workflow status NPM Version License: MIT

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

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.

See Also...

Package Sidebar

Install

npm i @chriscodesthings/compress-css-hex-color

Weekly Downloads

4

Version

1.1.1

License

MIT

Unpacked Size

8.18 kB

Total Files

8

Last publish

Collaborators

  • chriscodesthings