# color-model

> Operate colors in popular color models and convert between them

Latest version **0.2.2** (published 2015-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install color-model
pnpm add color-model
yarn add color-model
bun add color-model
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2015-02-08 |
| First published | 2014-03-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexander Ustimenko |
| Maintainers | garex |
| Keywords | color, model, convert, rgb, xyz, hex, hsv, lab |

## Links

- npm: https://www.npmjs.com/package/color-model
- Repository: https://github.com/garex/nodejs-color-model
- Issues: https://github.com/garex/nodejs-color-model/issues
- npm.io page: https://npm.io/package/color-model

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2015-02-08
- 0.2.1 — 2014-03-17
- 0.2.0 — 2014-03-15
- 0.1.2 — 2014-03-08
- 0.1.1 — 2014-03-03

## README

# Color model

Operate colors in popular color models: RGB, HSL, Lab and others.
Convert from each other.

## Usage

### Create new colors

    cm = require('color-model');
    
    xyz = new cm.Xyz(10, 20, 30);
    rgb = new cm.Rgb(10, 20, 30);
    rgb = new cm.HexRgb('#fff');
    hsl = new cm.Hsl(360, 100, 100);

### Convert colors between models

    rgb = new cm.HexRgb('#ffcc00');
    lab = rgbColor.toXyz().toLab();
    
    // and vice-versa
    hex = new cm.HexRgb('#ffcc00');
    lab = rgb.toXyz().toLab();
    hex = lab.toXyz().toRgb().toHex();

### Parse from HEX, do something and get back

    // desaturate and get back color as hex string
    hex = new cm.HexRgb('#ffcc00');
    hex.toHsl().saturation(0).toRgb().toString();
    
    // make from white black
    white = new cm.Rgb(255, 255, 255);
    black = white.red(0).green(0).blue(0);

## Images

![Base classes](https://raw.github.com/garex/nodejs-color-model/develop/docs/base-classes.png)

![All color models with convertions to each other](https://raw.github.com/garex/nodejs-color-model/develop/docs/all-models.png)

## Tests

Run `make test`. Currently code coverage is 99%.

## Copyright

(c) 2014 github.com/garex, a@ustimen.co

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