[6a3a178] | 1 | # Convert Colors [<img src="https://cdn.worldvectorlogo.com/logos/nodejs-icon.svg" alt="Convert Colors" width="90" height="90" align="right">][Convert Colors]
|
---|
| 2 |
|
---|
| 3 | [![NPM Version][npm-img]][npm-url]
|
---|
| 4 | [![Linux Build Status][cli-img]][cli-url]
|
---|
| 5 | [![Windows Build Status][win-img]][win-url]
|
---|
| 6 |
|
---|
| 7 | [Convert Colors] converts colors between RGB, HSL, HWB, Lab, LCH, HSV, and XYZ.
|
---|
| 8 |
|
---|
| 9 | ```js
|
---|
| 10 | import convert from '@csstools/convert-colors';
|
---|
| 11 |
|
---|
| 12 | convert.rgb2hsl(100, 100, 100); // [ 0, 0, 100 ]
|
---|
| 13 | convert.rgb2hwb(100, 100, 100); // [ 0, 100, 0 ]
|
---|
| 14 |
|
---|
| 15 | convert.hsl2rgb(0, 0, 100); // [ 0, 100, 0 ]
|
---|
| 16 | convert.hsl2hwb(0, 0, 100); // [ 0, 100, 0 ]
|
---|
| 17 |
|
---|
| 18 | convert.hwb2rgb(0, 100, 0); // [ 0, 0, 100 ]
|
---|
| 19 | convert.hwb2hsl(0, 100, 0); // [ 0, 0, 100 ]
|
---|
| 20 |
|
---|
| 21 | convert.rgb2hue(0, 0, 100); // 240
|
---|
| 22 | ```
|
---|
| 23 |
|
---|
| 24 | ## Usage
|
---|
| 25 |
|
---|
| 26 | Add [Convert Colors] to your build tool:
|
---|
| 27 |
|
---|
| 28 | ```bash
|
---|
| 29 | npm install @csstools/convert-colors --save-dev
|
---|
| 30 | ```
|
---|
| 31 |
|
---|
| 32 | ## Features
|
---|
| 33 |
|
---|
| 34 | Conversions work by taking arguments that represents a color in one color space
|
---|
| 35 | and returning an array of that same color in another color space.
|
---|
| 36 |
|
---|
| 37 | - rgb2hsl(r, g, b)
|
---|
| 38 | - rgb2hwb(r, g, b)
|
---|
| 39 | - rgb2lab(r, g, b)
|
---|
| 40 | - rgb2lch(r, g, b)
|
---|
| 41 | - rgb2hsv(r, g, b)
|
---|
| 42 | - rgb2xyz(r, g, b)
|
---|
| 43 | - hsl2rgb(h, s, l)
|
---|
| 44 | - hsl2hwb(h, s, l)
|
---|
| 45 | - hsl2lab(h, s, l)
|
---|
| 46 | - hsl2lch(h, s, l)
|
---|
| 47 | - hsl2hsv(h, s, l)
|
---|
| 48 | - hsl2xyz(h, s, l)
|
---|
| 49 | - hwb2rgb(h, w, b)
|
---|
| 50 | - hwb2hsl(h, w, b)
|
---|
| 51 | - hwb2lab(h, w, b)
|
---|
| 52 | - hwb2lch(h, w, b)
|
---|
| 53 | - hwb2hsv(h, w, b)
|
---|
| 54 | - hwb2xyz(h, w, b)
|
---|
| 55 | - lab2rgb(l, a, b)
|
---|
| 56 | - lab2hsl(l, a, b)
|
---|
| 57 | - lab2hwb(l, a, b)
|
---|
| 58 | - lab2lch(l, a, b)
|
---|
| 59 | - lab2hsv(l, a, b)
|
---|
| 60 | - lab2xyz(l, a, b)
|
---|
| 61 | - lch2rgb(l, c, h)
|
---|
| 62 | - lch2hsl(l, c, h)
|
---|
| 63 | - lch2hwb(l, c, h)
|
---|
| 64 | - lch2lab(l, c, h)
|
---|
| 65 | - lch2hsv(l, c, h)
|
---|
| 66 | - lch2xyz(l, c, h)
|
---|
| 67 | - hsv2rgb(h, s, v)
|
---|
| 68 | - hsv2hsl(h, s, v)
|
---|
| 69 | - hsv2hwb(h, s, v)
|
---|
| 70 | - hsv2lab(h, s, v)
|
---|
| 71 | - hsv2lch(h, s, v)
|
---|
| 72 | - hsv2xyz(h, s, v)
|
---|
| 73 | - xyz2rgb(x, y, z)
|
---|
| 74 | - xyz2hsl(x, y, z)
|
---|
| 75 | - xyz2hwb(x, y, z)
|
---|
| 76 | - xyz2lab(x, y, z)
|
---|
| 77 | - xyz2lch(x, y, z)
|
---|
| 78 | - xyz2hsv(x, y, z)
|
---|
| 79 |
|
---|
| 80 | [npm-url]: https://www.npmjs.com/package/@csstools/convert-colors
|
---|
| 81 | [npm-img]: https://img.shields.io/npm/v/@csstools/convert-colors.svg
|
---|
| 82 | [cli-url]: https://travis-ci.org/jonathantneal/convert-colors
|
---|
| 83 | [cli-img]: https://img.shields.io/travis/jonathantneal/convert-colors.svg
|
---|
| 84 | [win-url]: https://ci.appveyor.com/project/jonathantneal/convert-colors
|
---|
| 85 | [win-img]: https://img.shields.io/appveyor/ci/jonathantneal/convert-colors.svg
|
---|
| 86 |
|
---|
| 87 | [Convert Colors]: https://github.com/jonathantneal/convert-colors
|
---|