Precision, rounding and equality
A CSS string is an output format. If you plan to keep calculating with a color, keep the Color object or its tagged numeric channels.
Choose where to round
Hex and RGB strings round the sRGB channels to integers. Hex also rounds alpha to one byte. OKLCH strings keep five decimals for lightness and chroma and two for hue. Read channels with toObject() or toArray() when you need the numeric coordinates before formatting.
import { colore } from 'colore-js';
const color = colore('#2563eb');
const stored = color.toObject('srgb-linear');
console.log(colore(stored).equals(color, 0)); // true
Compare channels or appearance
equals() compares each linear RGB channel and alpha. Its default tolerance is 0.01; pass 0 for exact equality. For appearance, use deltaE for CIEDE2000 or deltaEOK for OKLab distance. Use a threshold chosen for that metric.
import { colore } from 'colore-js';
const black = colore('#000');
console.log(black.equals('#191919')); // true
console.log(black.deltaE('#191919').toFixed(2)); // '5.21'
Check a color after export
import { colore } from 'colore-js';
const gray = colore('rgb(118.6 118.6 118.6)');
console.log(gray.contrastRatio('#fff').toFixed(4)); // '4.5036'
console.log(gray.hex()); // '#777777'
console.log(colore(gray.hex()).contrastRatio('#fff').toFixed(4)); // '4.4781'
If you ship the hex value, use its ratio for the decision. At the 4.5:1 AA threshold for normal text, the difference changes the result.