color: immutable JavaScript color conversion, one chain at a time
GitHub describes it as :rainbow: Javascript color conversion and manipulation library. The repository metadata lists JavaScript as its primary language. The metadata lists the MIT license. This article stays within the project description and details documented in the GitHub repository README.
At a glance
- What is it?
- color converts and manipulates colors in JavaScript through immutable chains, with CSS string parsing handed to color-string and model conversion to color-convert. The short file never says how it fails, and its hex() note shows where alpha quietly disappears.
- Who is it for?
- color suits code that has to move a color between models, round it for output and check contrast without pulling a UI toolkit: it is three published files, two runtime dependencies and a Node 18 floor. It does not suit code that needs documented error handling or a contrast threshold helper, because neither appears in the file.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 51 days ago.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- Qix-/color4,934 ★ · -1
| Repository | 2026-08-13 | 2026-11-22 |
|---|---|---|
| Qix-/color | 4.9k | 4.9k |
-1 Stars in the last 101 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Every call returns a new value in a new model
The library describes itself as immutable, and the shape of the API follows from that: nothing mutates, so each call hands back a new color and the model you converted to sticks to it. The opening example does three conversions in one chain and prints all three results:
const color = Color('#7743CE').alpha(0.5).lighten(0.5);
console.log(color.hsl().string()); // 'hsla(262, 59%, 81%, 0.5)'
console.log(color.cmyk().round().array()); // [ 16, 25, 0, 8, 0.5 ]
console.log(color.ansi256().object()); // { ansi256: 183, alpha: 0.5 }Note what the keys are in each output. The HSL path produces a CSS string, the CMYK path an array of numbers with alpha last, and the ANSI 256 path a hash whose key is ansi256 with alpha beside it. Getter shape follows the current model, which is also why object() and array() are documented as reflecting the model rather than always returning RGB.
Install is one line, and the payload is three files
Getting it into a project takes one command:
npm install colorand one import:
import Color from 'color';The manifest decides what else you need to know. The package declares `"type": "module"` with a single export of ./index.js, so it is ESM-only and a CommonJS require has to become a dynamic import. Types come from ./index.d.ts, and the published files array contains exactly three entries: LICENSE, index.js and index.d.ts. Engines ask for Node 18 or newer, and sideEffects is false, which is a useful signal for tree shaking given that a single import pulls in conversion machinery. The license is MIT and the authors field lists Josh Junon, Heather Arthur and Maxime Thirouin.
Parsing belongs to color-string, and the hash key is valpha
Two runtime dependencies do the real work. String constructors are handled by color-string at version ^2.1.3, and model conversion by color-convert at ^3.1.3. The constructor examples show the internal shape, and one line is enough to expose the naming that trips people up:
const color = Color('hsl(194, 53%, 79%, 0.5)') // { model: 'hsl', color: [ 195, 53, 79 ], valpha: 0.5 }The alpha channel lives under valpha, not alpha, while hsl percentages arrive as plain numbers (53, 79). Hex input lands in the same rgb model, and a hex string with an alpha suffix is accepted too. Channel setters cover alpha, red, green, blue, hue, saturationl and saturationv for hsl and hsv, lightness, whiteness, blackness, cyan, magenta, yellow and black.
hex() drops alpha, hexa() keeps it
The one warning the file prints in bold is the one that costs the least to read and the most to skip: `.hex()` does not return alpha values, use `.hexa()` for an RGBA representation. That is a lossy default sitting next to a setter called alpha, and it is the trap for anyone storing theme colors or cache keys as hex strings. The neighbouring getters show how narrow the rest of the surface is:
color.object() // {r: 255, g: 255, b: 255}
color.rgbNumber() // 16777215 (0xffffff)
color.hex() // #ffffffobject() gives a hash, rgbNumber() collapses the color to a single integer, and hex() gives the familiar string. Only the last one is documented as dropping alpha, and index.d.ts in the repository root is where you would look for the full type surface, since the README shows only a handful of getter examples.
string() rounds to one decimal unless you say otherwise
Output formatting is one method with one optional argument:
color.hsl().string() // 'hsl(320, 50%, 100%)'Calling string() with a number rounds the numbers to that decimal place, and the default is 1. The file does not document a precision option for the array and object getters, so anything beyond the single decimal in string() has to be handled by your own rounding before you serialize it.
WCAG luminosity and contrast are built in
Three methods cover the accessibility question, and they implement the WCAG definitions rather than an approximation:
color.luminosity(); // 0.412Luminosity is the WCAG relative luminance, where 0 is black and 1 is white. contrast() returns the WCAG contrast ratio against another color, running from 1 for the same color to 21 for white against black, and the file's own example passes Color("blue") to get 12. Then there is the pair isLight() and isDark(), described as useful for deciding text color. What is absent is any threshold helper, so nothing here tells you which contrast value counts as acceptable; you pick the cutoff and the method just reports the number.
Manipulation clamps at both ends instead of wrapping
The manipulation functions behave the way the Sass, LESS and Stylus equivalents the file credits do, and the examples are chosen to show the edges:
color.lighten(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 75%)
color.lighten(0.5) // hsl(100, 50%, 0) -> hsl(100, 50%, 0)
color.darken(0.5) // hsl(100, 50%, 50%) -> hsl(100, 50%, 25%)
color.grayscale() // #5CBF54 -> #969696Lightening or darkening a color that is already at zero lightness leaves it at zero: the README maps hsl(100, 50%, 0) to hsl(100, 50%, 0) for both lighten(0.5) and darken(0.5). The set also covers negate, darken, lightness, saturate, desaturate and whiten, and the last section of the file, titled Propers, credits color-js for the API shape.
The lint config switches off seven rules, and the file ends there
The repository is small in the way a mature package is: .editorconfig, .npmrc, CONTRIBUTING.md, LICENSE, index.js, index.d.ts, index.test-d.ts, package.json and a test directory, with the default branch at master. The test script is `xo && tsd && mocha`, pinned to xo 0.60.0, tsd 0.31.2 and mocha 11.1.0, so linting, type tests and unit tests all gate a change. The xo configuration then turns seven rules off: no-bitwise, no-cond-assign, new-cap, unicorn/prefer-module, no-mixed-operators, complexity and unicorn/numeric-separators-style. Bitwise arithmetic and inline conditionals in a color library are unremarkable, but it does mean the style gate is looser than the default. The last push to master was on 2026-10-02 and the newest release is 5.0.3 from 2025-11-14, after 5.0.2 in September and 5.0.0 in February 2025. Nothing in the file covers error behaviour or a plugin API.
Editorial conclusion
color suits code that has to move a color between models, round it for output and check contrast without pulling a UI toolkit: it is three published files, two runtime dependencies and a Node 18 floor. It does not suit code that needs documented error handling or a contrast threshold helper, because neither appears in the file. Before adopting, check three things in your own codebase: whether your bundler is happy with an ESM-only package that declares sideEffects false, whether you are calling hex() on colors that carry an alpha channel, and whether the rounding you get from string() with no argument is the precision your output format expects.
Frequently asked questions
What is the color npm package used for?
Converting and manipulating colors in JavaScript with CSS string support, through immutable chains. The file shows conversion to rgb, hsl, cmyk and ansi256, CSS string output with optional rounding, and WCAG luminosity and contrast helpers for deciding text color.
How do I install and import the color package?
Run `npm install color` and then `import Color from 'color';`. The manifest declares `"type": "module"` with a single export of ./index.js and types from ./index.d.ts, so the package is ESM-only, and engines requires Node 18 or newer.
How do I keep the alpha channel when I convert to hex with color?
Use hexa() rather than hex(). The file states in a note that `.hex()` does not return alpha values and that hexa() gives the RGBA representation, while the alpha setter and the valpha key in the internal hash remain available for the channel itself.
Does the color library give me a contrast or readability check?
It gives the numbers, not the verdict. luminosity() returns the WCAG relative luminance from 0 (black) to 1 (white), contrast() returns the WCAG contrast ratio from 1 for the same color to 21 for white against black, and isLight() and isDark() report which side a color falls on.
Which color models can the color package output?
The file demonstrates rgb, hsl, cmyk and ansi256. Getters convert to a different space with calls such as hsl() or cmyk(), and object() and array() return a hash or an array reflecting the color's current model rather than always returning RGB.
How much does the color package ship?
Three files: LICENSE, index.js and index.d.ts, with sideEffects set to false and a single ./index.js export. Runtime work is delegated to color-convert at ^3.1.3 and color-string at ^2.1.3, and the test script is `xo && tsd && mocha`.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/qix-color)Star history chart for your README
[](https://hysenlabs.com/projects/qix-color)Was this useful?