color-parse is a fast and compact JavaScript library designed for parsing a wide array of CSS-compatible color strings into a structured object representation. It supports numerous formats including color keywords (e.g., 'red'), hex codes (`#RGB`, `#RRGGBB`, with optional alpha), functional notations like `rgb()`, `rgba()`, `hsl()`, `hsla()`, `hwb()`, `cmyk()`, and modern color spaces such as `xyz()`, `luv()`, `lab()`, `lch()`, `oklab()`, `oklch()`, and the generic `color()` function. Additionally, it can parse custom formats like `R:10 G:20 B:30` and array-like inputs. The library currently ships as version 2.0.2 and is actively maintained. It emphasizes performance and minimal bundle size, differentiating itself from alternatives by focusing solely on parsing without performing color space conversions, which helps keep its footprint small compared to libraries like `parse-color` or `color-string` that offer extensive conversion APIs.
npm install color-parseVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing various color formats including keywords, hex, HSLA, custom RGB, and the generic `color()` function, showing the structured output and error handling for unparseable strings.
Use a dedicated color conversion library in conjunction with `color-parse` for transformations.
Implement client-side validation for color component ranges if strict adherence to CSS color specification limits is required.
Ensure all inputs to the `parse` function are valid color strings.
Change the import statement to `import parse from 'color-parse';`
Review the input string to ensure it conforms to one of the supported CSS color formats or custom string patterns detailed in the documentation.
Always ensure the argument passed to `parse` is a valid string representation of a color.
No dependency data recorded yet.