Chromatism Color Utilities

3.0.0 · active · verified Sun Apr 19

Chromatism is a lightweight JavaScript utility library designed for comprehensive color manipulation, offering a rich set of functions for color transformations, conversions, and metering. It supports various color types including RGB, HSL, Hex, CMYK, and can intelligently process mixed input types. The current stable version is 3.0.0, which marked a significant breaking change focused on optimizing for ES Modules (ESM) to achieve the smallest possible bundle sizes. Key differentiators include its strong emphasis on ESM for tree-shaking, the implementation of uniform hue-shifting transforms using HSLuv for more accurate color adjustments, and an efficient internal conversion chain. The library also ships with first-class TypeScript definitions, enhancing developer experience and type safety. While previous major versions supported function chaining, v3.0.0 removed this pattern in favor of a more functional, direct API.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates core color manipulation functions like conversion, shading, inversion, and generating complementary colors, showcasing various input/output formats.

import { convert, shade, invert, complementary, rgb } from 'chromatism';

// Start with a hex color
const baseHex = '#FF6347'; // Tomato

// Convert to RGB and then apply a shade adjustment
const shadedColor = shade(15, convert(baseHex).rgb);
console.log('Shaded Color (RGB):', shadedColor.rgb); // Access specific format
console.log('Shaded Color (HEX):', shadedColor.hex);

// Get the complementary color in HSL
const complementaryColor = complementary(baseHex).hsl;
console.log('Complementary Color (HSL):', complementaryColor);

// Invert the original color
const invertedColor = invert(baseHex).rgb;
console.log('Inverted Color (RGB):', invertedColor);

// Example with direct RGB input and brightness adjustment
const newColor = rgb(255, 0, 0); // Red
const brighterRed = shade(-20, newColor); // shade can also brighten
console.log('Brighter Red (HEX):', brighterRed.hex);

view raw JSON →