Fast and compact color string parser.
$ npm install color-parse
importparsefrom'color-parse'parse('hsla(12 10% 50% / .3)')// { space: 'hsl', values: [12, 10, 50], alpha: 0.3 }- Color keywords:
red,greenetc., see color-name #RGB[A]#RRGGBB[AA]rgb[a](R, G, B[, A])rgb(R G B[ / A])hsl[a](H, S, L[, A]), inc. named hueshsl(H S L [ / A])hwb(H, W, B)cmyk(C, M, Y, K)xyz(X, Y, Z)luv(L, U, V)luv(L U V[ / A])lab(L, A, B)lab(L a b[ / A])- see limitslch(L, C, H)lch(L C H[ / A])- see limitsoklab(L a b[ / A])- see limitsoklch(L C H[ / A])- see limitscolor(space c1 c2 c3[ / A])R:10 G:20 B:30[ A:0.5], decimals and negatives includedL 0.39 C 0.083 H 153(R10 / G20 / B30)C100/M80/Y0/K35[10, 20, 20]as RGB10,20,20[,0.5]as RGB[A]0x00ff00,0x0000ffnumbers as RGB
- unknown strings eg.
'yellowblue' - malformed hex eg.
#zzz,#12345 - not strings: object, arrays etc.
- color-space — collection of color space conversions.
- color-rgba — convert any color string to rgba array.
- color-alpha — change alpha component of any color.
- 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.