open-index/open-npm huggingface dataset:
npm package: @magedragonfrog/css-color-parser
Description: Parses colors according to the CSS Color Module Level 4 W3C specification
Author: federico-paolillo
Latest version: 2.2.0
Deprecated: Discontinued

# `@magedragonfrog/css-color-parser`

Parses color values specified in CSS style properties.  
Implements a subset of the [CSS Color Module - Level 4](https://www.w3.org/TR/css-color-4) specification.  

## Usage

First off you need to install the package from NPM using `npm install --save @magedragonfrog\css-color-parser`.  
Once the package is installed you can import the `parseColor` function from `@magedragonfrog\css-color-parser`.  
For example:

```javascript
import { parseColor } from '@magedragonfrog\css-color-parser'

const result: RGBColor = parseColor('cadetblue');

console.log(`Red component is: ${result.r}, green component is: ${result.g}, blue component is: ${result.b}`);

//Prints: Red component is: 0.37, green component is: 0.62, blue component is: 0.63
```

`parseColor` always returns an `RGBColor` object that has three properties: `r`, `g`, `b`.  
Each property value is the corresponding color component value between 0 and 1.  

At the moment the alpha component **is not supported** and is ignored.  
If a color is not recognized the function returns the `RGBColor` representation for the color white (i.e.: all the components are 0).  

## Color representations supported

For now only some representations are supported.  
More will be added in the future.   

- [RGB functions](https://www.w3.org/TR/css-color-4/#rgb-functions)
- [RGB hexdecimal notations](https://www.w3.org/TR/css-color-4/#hex-notation)
- [Named colors](https://www.w3.org/TR/css-color-4/#named-colors)

## Limitations

- At the moment the alpha component **is not supported** and is ignored.
- Not all color representations are supported