# color-parse [![test](https://github.com/colorjs/color-parse/actions/workflows/test.js.yml/badge.svg)](https://github.com/colorjs/color-parse/actions/workflows/test.js.yml) [![size](https://img.shields.io/bundlephobia/minzip/color-parse?label=size)](https://bundlephobia.com/result?p=color-parse) ![stable](https://img.shields.io/badge/stability-stable-green) Fast and compact color string parser. `$ npm install color-parse` ```js var parse = require('color-parse') parse('hsla(12 10% 50% / .3)') // { space: 'hsl', values: [12, 10, 50], alpha: 0.3 } ``` ## Parsed strings * [x] Color keywords: `red`, `green` etc., see [color-name](https://ghub.io/color-name) * [x] `#RGB[A]` * [x] `#RRGGBB[AA]` * [x] `rgb[a](R, G, B[, A])` * [x] `rgb(R G B[ / A])` * [x] `hsl[a](H, S, L[, A])`, inc. [named hues](http://dev.w3.org/csswg/css-color/#simple-hues) * [x] `hsl(H S L [ / A])` * [x] `hwb(H, W, B)` * [x] `cmyk(C, M, Y, K)` * [x] `xyz(X, Y, Z)` * [x] `luv(L, U, V)` * [x] `luv(L U V[ / A])` * [x] `lab(L, A, B)` * [x] `lab(L a b[ / A])` - see [limits](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lab) * [x] `lch(L, C, H)` * [x] `lch(L C H[ / A])` - see [limits](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch) * [x] `oklab(L a b[ / A])` - see [limits](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklab) * [x] `oklch(L C H[ / A])` - see [limits](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/oklch) * [x] `color(space c1 c2 c3[ / A])` * [x] `R:10 G:20 B:30` * [x] `(R10 / G20 / B30)` * [x] `C100/M80/Y0/K35` * [x] `[10, 20, 20]` as RGB * [x] `10,20,20` as RGB * [x] `0x00ff00`, `0x0000ff` numbers as RGB ## Not parsed * [x] unknown strings eg. `'yellowblue'` * [x] not strings: object, arrays etc. ## Related * [color-space](https://npmjs.org/package/color-space) — collection of color space conversions. * [color-rgba](https://npmjs.org/package/color-rgba) — convert any color string to rgba array. * [color-alpha](https://npmjs.org/package/color-alpha) — change alpha component of any color. ## Analogs * [parse-color](http://npmjs.org/package/parse-color) — parser by @substack. Performs calculations to every possible space, which bloats size. * [color-parser](http://npmjs.org/package/color-parser) — parser by @tjholowaychuk. Supports limited set of spaces. * [color-string](http://npmjs.org/package/color-string) — parsing/serializing module by Heather Arthur. Has extensive API for parsing and serializing from any to any space. [![NPM](https://nodei.co/npm/color-parse.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/color-parse/)