Colore JS

Search documentation

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

Performance and bundling

Import what you use. A named function from colore-js/fn fits an isolated conversion or edit. A Color object is useful when several operations work on the same input.

Choose an import

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

console.log(lighten('#2563eb', 8)); // '#306ff8'

Named imports let your bundler drop unused exports. One function still includes the parser it needs for named colors, supported CSS functions and tagged objects.

What an import costs

These are approximate gzip sizes for the local Colore v2 build, measured with Rollup 4.59, Terser 5.31 and gzip level 9. Measure your own production bundle to see what the rest of your app shares.

ImportGzip
toHex from colore-js/fn10 KiB
ensureContrast from colore-js/fn14 KiB
colore() / Color class18 KiB
audit from colore-js/fn25 KiB
generateSystem from colore-js/fn33 KiB
All root exports39 KiB

Parse once for several changes

import { colore } from 'colore-js';

const input = colore('#7c3aed');
console.log(input.lighten(8).saturate(6).css()); // 'color(display-p3 0.49629 0.27042 0.97260)'

The chain keeps the working color in memory until you call css(). Passing a CSS string from one standalone transform to the next formats and parses an intermediate value. For a palette you use on every render, compute it when its input changes.

Run the benchmarks

With the repo dependencies installed, build the package at the repo root and run its quick benchmark.

yarn build
yarn bench:quick

The runner measures parse-plus-hex, parse-plus-RGB and WCAG contrast on 256 opaque sRGB hex inputs or pairs. Each reported operation is a full pass over its dataset. For an app decision, also measure the color formats and operations your users run.