npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

haus-colour-utils

v1.0.0

Published

Perceptual colour utilities: CIEDE2000 distance, WCAG contrast, OKLCH lightness scales, and nearest-named-colour.

Readme

haus-colour-utils

Perceptual colour utilities: the colour science behind the haus design system, published standalone. Pure ESM, ships its own types, one dependency.

npm install haus-colour-utils

API

import {
  deltaE,
  wcagContrast,
  clusterByPerceptualDistance,
  nearestNamedColour,
  createNamedColourMatcher,
  generateLightnessScale,
  oklch,
  hueFamily,
  isLight,
  suggestTextColour,
} from "haus-colour-utils";

deltaE(a, b): number

CIEDE2000 perceptual distance between two hex colours. < 1 is imperceptible; < 2 is a just-noticeable difference.

deltaE("#3366cc", "#3467cc"); // 0.34, effectively the same colour

wcagContrast(foreground, background): ContrastResult

WCAG 2.1 contrast ratio and pass/fail verdicts.

wcagContrast("#767676", "#ffffff");
// { ratio: 4.54, passAA: true, passAAA: false, passAALarge: true }

clusterByPerceptualDistance(hexes, threshold?): ColourCluster[]

Group colours that are perceptually within threshold ΔE of each other (default 8). This is the basis for finding near-duplicate tokens.

nearestNamedColour(hex, topN?): NamedColourMatch[]

The closest named colours to a hex, ranked by CIEDE2000 distance, over the 289 basic colour terms bundled here.

createNamedColourMatcher(entries): (hex, topN?) => NamedColourMatch[]

The same search over a dataset you supply. Install haus-colour-names for the exhaustive 31,900-name set:

import { colourNameEntries } from "haus-colour-names";
const nameColour = createNamedColourMatcher(colourNameEntries());

Both rank on the true CIEDE2000 distance and round only the number they report, so a candidate 0.96 away outranks one 1.00 away even though both display as 1. Equal distances break by name, so the result does not depend on the order the dataset happens to be in.

oklch(hex): Oklch | null

Lightness, chroma and hue. h is null for an achromatic colour, so a grey cannot silently propagate a NaN.

oklch("#ff0000"); // { l: 0.628, c: 0.258, h: 29.2 }

hueFamily(hex, families?, neutralChroma?): string | null

Which named family a colour belongs to: one of HUE_FAMILIES, or "Neutral" below NEUTRAL_CHROMA (0.03).

hueFamily("#2563eb"); // "Blue"
hueFamily("#f7f7fa"); // "Neutral". A tinted near-white is still a grey.

Chroma rather than HSL saturation, which inflates at the extremes of lightness and reads a tinted near-black as a saturated hue. The bins are fitted to 4,275 colours a person named, taken from haus-colour-names: the boundaries are the set that maximises mean per-family recall, and hue-families.test.ts holds it at 0.77. They are not the HSL wheel's boundaries, which offset every family by about one place, and they are no longer midpoints between the eight colours the families are named after. That construction assumed a family is centred on its namesake, and several are not: the median of 222 colours people call orange is hue 47, while #ffa500 is at 71, so a midpoint at 50 filed most oranges as red.

generateLightnessScale(hex, options?): string[]

A perceptual lightness ramp anchored on a colour, in OKLCH. Options: { steps = 10, minL = 8, maxL = 97 }.

isLight(hex): boolean · suggestTextColour(background, palette): string

Quick helpers for picking readable text against a background.

Licence

MIT.