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

@crisvsgame/chroma

v1.1.0

Published

A lightweight colour utility library for sRGB conversion, luminance, contrast, and colour generation

Readme

Chroma

RGB Contrast Utility Library

Chroma is a lightweight, fully typed TypeScript utility library for working with CSS RGB colours, random colour generation, and WCAG contrast ratios.

It is designed for simple browser and canvas use cases where colours need to be generated, converted to CSS, or adjusted to meet accessible contrast levels.


📦 Installation

Install from npm:

npm install @crisvsgame/chroma

Import the main class:

import { Chroma } from "@crisvsgame/chroma";

🚀 Quick Start

import { Chroma } from "@crisvsgame/chroma";

const bg = Chroma.randomRgb();
const fg = Chroma.randomWithContrast(bg);

document.body.style.backgroundColor = Chroma.rgbToCss(bg);
document.body.style.color = Chroma.rgbToCss(fg);

Generate a random accessible colour pair:

const { bg, fg } = Chroma.randomPair();

console.log(Chroma.rgbToCss(bg));
console.log(Chroma.rgbToCss(fg));
console.log(Chroma.contrast(bg, fg));

🌐 CDN / Browser ESM

Chroma can also be imported directly in the browser through jsDelivr:

<script type="module">
    import { Chroma } from "https://cdn.jsdelivr.net/npm/@crisvsgame/[email protected]/dist/index.js";

    const { bg, fg } = Chroma.randomPair();

    document.body.style.backgroundColor = Chroma.rgbToCss(bg);
    document.body.style.color = Chroma.rgbToCss(fg);
</script>

🔧 Features

  • Random integer generation
  • Random float generation
  • Random RGB colour generation
  • RGB to CSS rgb(...) conversion
  • WCAG contrast ratio calculation
  • WCAG AA/AAA contrast constants
  • Contrast checking
  • Contrast adjustment
  • Random accessible colour pairs
  • Zero runtime dependencies
  • Fully typed TypeScript API

♿ WCAG Constants

Chroma.WCAG_AA_LARGE; // 3
Chroma.WCAG_AA_NORMAL; // 4.5
Chroma.WCAG_AAA_LARGE; // 4.5
Chroma.WCAG_AAA_NORMAL; // 7

🎨 Public API

Chroma.randomInt(min, max);
Chroma.randomFloat(min, max);
Chroma.randomRgb();
Chroma.rgbToCss(rgb);
Chroma.contrast(first, second);
Chroma.meetsContrast(first, second, ratio);
Chroma.adjustToContrast(base, color, options);
Chroma.randomWithContrast(base, options);
Chroma.randomPair();

Fully typed imports:

import { Chroma, VERSION, type Rgb, type RgbPair, type ContrastOptions, type ContrastDirection } from "@crisvsgame/chroma";

console.log(VERSION);

📂 Project Structure

src/
    Chroma.ts
    index.ts
test/
    Chroma.test.ts
dist/ # generated build output published to npm
    Chroma.d.ts
    Chroma.d.ts.map
    Chroma.js
    Chroma.js.map
    index.d.ts
    index.d.ts.map
    index.js
    index.js.map
.gitignore
LICENSE
README.md
package-lock.json
package.json
tsconfig.json

🧪 Testing

Run the test suite:

npm test

The tests cover public API behaviour, validation, random helper invariants, and WCAG contrast guarantees.


🛠️ Build

Build the library:

npm run build

📝 License

MIT License


🔗 Links

  • npm: https://www.npmjs.com/package/@crisvsgame/chroma
  • Source Code: https://github.com/CRISvsGAME/chroma