Colore JS

Search documentation

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

deltaE

deltaE measures CIEDE2000 color difference in JavaScript. Use it to compare a target and sample when your workflow specifies ΔE00. You can set your own weights for lightness, chroma and hue.

Example

import { colore } from 'colore-js';
import { deltaE } from 'colore-js/fn';

colore('#7c3aed').deltaE('#7b3ae8').toFixed(3); // '0.647'
deltaE('#7c3aed', '#2563eb').toFixed(3);        // '18.267'

Syntax

colore(first).deltaE(second: ColorInput | Color, kL?: number, kC?: number, kH?: number): number
deltaE(first: ColorInput, second: ColorInput, kL?: number, kC?: number, kH?: number): number

Parameters

NameTypeDescription
first, secondColorInputThe two colors to compare. The method can also take a Color.
kL, kC, kHnumberOptional weighting factors for lightness, chroma and hue. Each defaults to 1. Larger values reduce the contribution of that channel.

Returns

Both APIs return a nonnegative ΔE00 number. Alpha is ignored, so colors with identical channels and different opacity have distance zero.

Throws

A ColorError if a color cannot be parsed or a weighting factor is non-finite or at most zero.

Compare samples with lightness weighted down

import { deltaE } from 'colore-js/fn';

deltaE('#7c3aed', '#7b3ae8', 1).toFixed(3); // '0.647'
deltaE('#7c3aed', '#7b3ae8', 2).toFixed(3); // '0.518'

Use the same formula and weights as the specification you are comparing against. Pick a tolerance for your use case and compare the unrounded value in code.