csscolorparser is a lightweight JavaScript utility designed to parse CSS color strings into an RGBA array. It was initially released in 2012 and has not seen updates since version 1.0.3, published approximately 9 years ago. The package directly exports a single function, `parseCSSColor`, which takes a string (e.g., 'rgba(255, 128, 12, 0.5)', '#fff', 'slateblue') and returns a four-element array `[R, G, B, A]` where R, G, B are integers (0-255) and A is a float (0-1), or `null` for invalid input. Its primary differentiator is its simplicity and lack of dependencies, but its age means it only supports older CSS Color Module Level 3/4 formats and lacks support for newer specifications like HWB, LAB, LCH, Oklab, Oklch, or the `color()` function. It operates as a CommonJS module with interop for ESM.
npm install csscolorparserVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing the default `parseCSSColor` function and using it to parse various valid and invalid CSS color strings, logging the RGBA array or null.
Manually validate results or use a more actively maintained CSS color parser for strict spec compliance.
Always provide an explicit alpha value for `hsla` if expecting a non-null output, or use `hsl()` for opaque colors. Example: `parseCSSColor('hsla(900, 15%, 90%, 1)')`.For modern CSS color parsing capabilities, consider actively maintained alternatives like `@csstools/css-color-parser` or `color.js`.
Ensure all hexadecimal color strings include the leading `#` symbol. Example: `parseCSSColor('#ffffff')`.Use a default import for ESM (`import parseCSSColor from 'csscolorparser';`) or `require()` for CommonJS (`const parseCSSColor = require('csscolorparser');`).Ensure the import statement is `import parseCSSColor from 'csscolorparser';` for ESM or `const parseCSSColor = require('csscolorparser');` for CommonJS. Do not use `import { parseCSSColor } from 'csscolorparser';`.Add the `#` prefix to all hexadecimal color strings: `parseCSSColor('#ffffff')`.Provide an explicit alpha value: `parseCSSColor('hsla(120, 50%, 50%, 1)')` or use `hsl()` which implicitly has alpha `1`: `parseCSSColor('hsl(120, 50%, 50%)')`.No dependency data recorded yet.