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

1.1.1 • Public • Published

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

Expands a CSS hex color to it's longest form

Description

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

See...


Install

npm install --save @chriscodesthings/expand-css-hex-color

Use

import expandCSSHexColor from '@chriscodesthings/expand-css-hex-color';

console.log(expandCSSHexColor("#cafe"));
// => #ccaaffee

Types

This package uses types from:

Syntax

expandCSSHexColor(color);

Parameters

  • color: a CSS hex color string

Return Value

Returns the longest form of the CSS color code.

Examples

// 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
}

See Also...

Readme

Keywords

Package Sidebar

Install

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

Weekly Downloads

2

Version

1.1.1

License

MIT

Unpacked Size

7.68 kB

Total Files

8

Last publish

Collaborators

  • chriscodesthings