color-string is a focused utility library for parsing and generating CSS-compatible color strings, supporting various formats like RGB, HSL, HWB, and named colors. The current stable version is 2.1.4. The library maintains a reasonably active release cadence, with recent updates introducing features like case-insensitive string checks and improved parsing for modern CSS color notations, alongside crucial bug fixes. Its key differentiators include its lightweight nature, explicit support for multiple color models, and direct conversion capabilities to and from different string representations, making it a reliable choice for frontend and backend color manipulation tasks where CSS compatibility is paramount. It ships with TypeScript types for enhanced developer experience.
npm install color-stringVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing various CSS color strings and generating color strings in different formats (hex, rgb, rgba), including handling invalid input.
Migrate your codebase to use ES module `import` syntax. For Node.js, ensure your `package.json` has `"type": "module"` or use `.mjs` file extensions. If stuck on CommonJS, consider using a bundler like Webpack or Rollup, or stick to an older `1.x.x` version.
Refactor your code to no longer depend on 'swizzle'. This might involve using direct color conversion functions or finding an alternative library for color component manipulation.
Ensure your code checks for `null` when handling potentially invalid color string results from `colorString.get()` or its sub-methods.
Immediately upgrade to version `2.1.2` or higher. Do not use `2.1.1` under any circumstances. Check your `package-lock.json` or `yarn.lock` files.
Upgrade to version `2.1.3` or newer to ensure correct parsing of named colors into RGB values.
Review any code that might depend on strict case-sensitive parsing of color string models. Most applications will benefit from this change, but it's a behavioral shift.
Use `import colorString from 'color-string';` instead of `require()`. For Node.js, ensure your environment is configured for ESM (e.g., `"type": "module"` in `package.json`).
Upgrade `color-string` to version `2.1.3` or newer.
Always check if the result of `colorString.get()` or its sub-methods is `null` before attempting to access its properties. For TypeScript, use optional chaining or a null check, e.g., `const parsed = colorString.get(str); if (parsed) { console.log(parsed.model); }`.No dependency data recorded yet.