Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

Color utilities

Check a color before you branch on it. You can read opacity, test equality, check the gamut or find out whether the color is light or dark.

Example

import { colore } from 'colore-js';

const blue = colore('#2563eb80');
console.log(blue.alpha().toFixed(3)); // '0.502'
console.log(blue.format()); // 'hex-alpha'
console.log(colore('#111827').isDark()); // true

Syntax

MethodReturns or changes
alpha()Opacity as a number from 0 to 1
clone()A new Color with the same channels
equals(other, tolerance?)A boolean based on linear RGB and alpha, with a tolerance of 0.01 by default
isInGamut(space?)A boolean for 'srgb' (default) or 'p3'
toGamut(space?)A Color mapped into 'srgb' (default) or 'p3'
format()The format label Colore recorded for the color
luminance()Relative luminance as a number
isLight(), isDark()A boolean classifying the color by luminance

Throws

A ColorError if a gamut name is unknown, the comparison color is invalid, or the tolerance is negative or non-finite.

Check exact equality before exporting

import { colore } from 'colore-js';

const black = colore('#000');
console.log(black.equals('#191919')); // true
console.log(black.equals('#191919', 0)); // false

Set the tolerance to 0 to compare exact channel values. For similarity by appearance, choose deltaE or deltaEOK. For readable text, measure contrast against its background.