npm

color-parse
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

color-parse test size stable

Fast and compact color string parser.

$ npm install color-parse

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
  • [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
  • [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
  • [x] lch(L, C, H)
  • [x] lch(L C H[ / A]) - see limits
  • [x] oklab(L a b[ / A]) - see limits
  • [x] oklch(L C H[ / A]) - see limits
  • [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 — collection of color space conversions.
  • color-rgba — convert any color string to rgba array.
  • color-alpha — change alpha component of any color.

Analogs

  • parse-color — parser by @substack. Performs calculations to every possible space, which bloats size.
  • color-parser — parser by @tjholowaychuk. Supports limited set of spaces.
  • color-string — parsing/serializing module by Heather Arthur. Has extensive API for parsing and serializing from any to any space.

NPM

Package Sidebar

Install

npm i color-parse

Weekly Downloads

629,689

Version

2.0.2

License

MIT

Unpacked Size

21 kB

Total Files

8

Last publish

Collaborators

  • dfcreative
  • dy