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

1.1.2 • 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

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.

See Also...

Dependencies (1)

Dev Dependencies (3)

Package Sidebar

Install

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

Weekly Downloads

2

Version

1.1.2

License

MIT

Unpacked Size

9.15 kB

Total Files

8

Last publish

Collaborators

  • chriscodesthings