Registry / serialization / color-stringify

color-stringify

JSON →
library1.2.1jsnpmunverified

color-stringify is a JavaScript utility for converting various color value representations (like arrays of RGB/HSL components or objects) into standard CSS color strings. It supports outputting in formats such as hex (`#RRGGBB`), keywords (`red`), percentage (`rgb(10%, 20%, 30%)`), and several Adobe-specific formats, alongside the default `rgba()` or `hsla()` output. The library is currently at version 1.2.1, with its last update in early 2019, suggesting an abandoned or maintenance-only release cadence. It differentiates itself by offering a specific utility for stringifying pre-parsed color values, often paired with a parsing library like `color-parse`.

npm install color-stringify
INSTALL
IMPORT
SIG · COLOR-STRINGIFY
C
color-stringify
serializationjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

stringify
const stringify = require('color-stringify');
import stringify from 'color-stringify';
This package is CommonJS-only and does not provide an ES module export. Use `require()`.
stringify
const { stringify } = require('color-stringify');
import { stringify } from 'color-stringify';
While `require('color-stringify')` returns the function directly, destructuring can also be used if the module's default export is `module.exports = stringify`.

Demonstrates stringifying various color formats (arrays, objects) into different CSS string types using the `stringify` function.

const stringify = require('color-stringify'); // Example 1: HSL array to HSLA string const hslaString = stringify([120, 100, 100, 0.4], 'hsl'); console.log(`HSL array to HSLA: ${hslaString}`); // Expected: hsla(120, 100%, 100%, .4) // Example 2: RGB array to default RGBA string const rgbaString = stringify([255, 0, 128, 0.75]); console.log(`RGB array to RGBA: ${rgbaString}`); // Expected: rgba(255, 0, 128, 0.75) // Example 3: RGB object (from color-parse) to HEX string const colorObject = { r: 51, g: 153, b: 255, alpha: 1, type: 'rgb' }; const hexString = stringify(colorObject, 'hex'); console.log(`RGB object to HEX: ${hexString}`); // Expected: #3399FF // Example 4: RGB array to keyword (if available) const keywordString = stringify([255, 0, 0], 'keyword'); console.log(`RGB array to keyword: ${keywordString}`); // Expected: red
Debug
Known issues
breakingThis package is CommonJS-only and does not provide native ES module exports. Direct `import` statements will fail in pure ESM environments or modern Node.js versions without specific configurations (e.g., `--experimental-json-modules` or transpilation).
fix
Use `const stringify = require('color-stringify');` instead of `import` statements. For ESM projects, consider using a compatibility layer or a modern alternative that supports ESM.
affects: >=1.0.0
gotchaThe package has not been updated since February 2019 (version 1.2.1). This indicates it is no longer actively maintained and may not be compatible with newer JavaScript features, environments, or security standards. There are no TypeScript definitions shipped with the package.
fix
Review the source code for potential vulnerabilities or compatibility issues before integrating into critical applications. Consider migrating to a more actively maintained color utility library for modern projects, especially those requiring ESM or TypeScript support.
affects: >=1.0.0
gotchaWhen using `type: 'keyword'`, the input color must exactly match a known CSS color name's RGB value. If no exact match is found, it will fall back to a default `rgba()` representation, which might be unexpected.
fix
Ensure the input color corresponds to a standard CSS color keyword for reliable keyword output. Otherwise, use `undefined` or another specific type like `hex` or `rgb`.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... From `color-stringify`
`color-stringify` is a CommonJS module being imported into an ES module context without proper interoperability.
fix
If in a modern Node.js ESM module (e.g., `"type": "module"` in `package.json`), you cannot directly `require()` a CJS module in all cases. Try `import * as stringify from 'color-stringify';` or consider a CJS-compatible wrapper, but the most reliable fix is often to use `require()` in a CJS context or migrate to an ESM-first alternative. For this specific package, revert to CJS usage if possible: `const stringify = require('color-stringify');`.
TypeError: stringify is not a function
Incorrect import of the `stringify` function. If you used `import { stringify } from 'color-stringify';` in a CJS context, or if `require('color-stringify')` returned an object instead of the function itself.
fix
Ensure you are using `const stringify = require('color-stringify');` as the package exports the function directly as `module.exports`. If you are in an ESM context trying to import, see the `ERR_REQUIRE_ESM` warning.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
color-namerequiredProvides a list of CSS color keywords for 'keyword' output type.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
color-stringify — npm install color-stringify · libregistry