# css-color-converter

> Converts CSS colors from one representation to another

Latest version **2.0.0** (published 2020-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install css-color-converter
pnpm add css-color-converter
yarn add css-color-converter
bun add css-color-converter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-09-24 |
| First published | 2015-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Andy Jansson |
| Maintainers | andyjansson |
| Keywords | css, color, conversions, converter |

## Links

- npm: https://www.npmjs.com/package/css-color-converter
- Repository: https://github.com/andyjansson/css-color-converter
- Issues: https://github.com/andyjansson/css-color-converter/issues
- npm.io page: https://npm.io/package/css-color-converter

## Dependencies (3)

- [color-name](https://npm.io/package/color-name.md) ^1.1.4
- [color-convert](https://npm.io/package/color-convert.md) ^0.5.2
- [css-unit-converter](https://npm.io/package/css-unit-converter.md) ^1.1.2

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-09-24
- 1.1.1 — 2020-03-20
- 1.1.0 — 2016-08-13
- 1.0.2 — 2015-05-27
- 1.0.1 — 2015-05-27
- 1.0.0 — 2015-05-27

## README

# css-color-converter [![Build Status][ci-img]][ci]

Converts CSS colors from one representation to another 

[ci-img]:  https://travis-ci.org/andyjansson/css-color-converter.svg
[ci]:      https://travis-ci.org/andyjansson/css-color-converter

## Installation

```js
npm install css-color-converter
```

## Usage

**Example usage**: 
```js
import { fromString } from 'css-color-converter';

fromString('rgb(255, 255, 255)').toHslString(); // hsl(0, 0%, 100%)
fromString('rgba(255, 255, 255, 0.5)').toHslString(); // hsla(0, 0%, 100%, 0.5)
fromString('blue').toRgbString(); // rgb(0, 0, 255)
fromString('red').toHexString(); // #ff0000
```
## Functions

### `fromString(str)`
| parameter | type   | description                                    |
| --------- | ------ | ---------------------------------------------- |
| `str`     | string | Supports named colors, hex, rgb/rgba, hsl/hsla |

**Returns** [`instance`](#Methods) if valid, `null` if invalid.

### `fromRgb([r, g, b])`

| parameter | type   | description   |
| --------- | ------ | ------------- |
| `r`       | int    | red (0-255)   |
| `g`       | int    | green (0-255) |
| `b`       | int    | blue (0-255)  |

**Returns** [`instance`](#Methods)

### `fromRgba([r, g, b, a])`

| parameter | type   | description   |
| --------- | ------ | ------------- |
| `r`       | int    | red (0-255)   |
| `g`       | int    | green (0-255) |
| `b`       | int    | blue (0-255)  |
| `a`       | float  | alpha (0-1)   |

**Returns** [`instance`](#Methods)

### `fromHsl([h, s, l])`

| parameter | type   | description        |
| --------- | ------ | ------------------ |
| `h`       | int    | hue (0-360)        |
| `s`       | int    | saturation (0-100) |
| `l`       | int    | luminosity (0-100) |

**Returns** [`instance`](#Methods)

### `fromHsla([h, s, l, a])`

| parameter | type   | description        |
| --------- | ------ | ------------------ |
| `h`       | int    | hue (0-360)        |
| `s`       | int    | saturation (0-100) |
| `l`       | int    | luminosity (0-100) |
| `a`       | float  | alpha (0-1)        |

**Returns** [`instance`](#Methods)

## Methods

### `toRgbString()`

**Returns** `rgb()` or `rgba()`, depending on the alpha.

### `toHslString()`

**Returns** `hsl()` or `hsla()`, depending on the alpha.

### `toHexString()`

**Returns** 6-digit or 8-digit `hex`, depending on the alpha.

### `toRgbaArray()`

**Returns** `[r, g, b, a]` array.

---
_Source: https://npm.io/package/css-color-converter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
