Color is a JavaScript library for immutable color parsing, conversion, and manipulation. It accepts CSS color strings and exposes channels, string output, luminosity, and contrast helpers.
Overview
Color is a JavaScript package for working with colors as immutable values. Constructors accept CSS color strings handled via color-string, and individual channels such as alpha, RGB, HSL, HSV, CMYK, and related components can be read or updated.
Converters produce values in spaces like HSL or CMYK, and getters expose hex, RGB numbers, arrays, and hashes reflecting the active model. String output can round decimals for CSS emission.
Luminosity helpers implement WCAG luminance and contrast ratios between two colors, plus simple light-or-dark checks useful when picking text colors. Manipulation APIs mirror common CSS preprocessor-style adjustments inspired by color-js and tools like Sass.
The library focuses on accurate conversions and predictable object behavior without mutating prior instances.
Key features
- CSS color string parsing
- Multi-space color conversion
- Hex, RGB, and array export
- WCAG luminance and contrast
- Light and dark detection
- Preprocessor-style manipulations
Use cases
- Converting colors in JavaScript apps
- Computing contrast for accessible text
- Building design or theme tooling
- Normalizing user-supplied CSS colors