Color Stringifier

1.2.1 · abandoned · verified Tue Apr 21

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`.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →