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

@laboralphy/rainbow

v3.0.0

Published

This package provides functions for parsing, structuring colors and generating gradients.

Readme

@laboralphy/rainbow

Parse, convert, render and interpolate colors. Written in TypeScript, published for both TypeScript and JavaScript projects (ESM and CommonJS).

Install

npm install @laboralphy/rainbow

Usage

TypeScript / ESM:

import { Rainbow } from '@laboralphy/rainbow';
import type { Color32 } from '@laboralphy/rainbow';

const purple: Color32 = Rainbow.parse('rebeccapurple');

Rainbow.renderHex6(purple); // '#663399'
Rainbow.renderRGBA(purple); // 'rgba(102, 51, 153, 1)'
Rainbow.convertToHSLA(purple); // { h: 0.75, s: ~0.5, l: 0.4, a: 1 }

CommonJS:

const { Rainbow } = require('@laboralphy/rainbow');

Rainbow.renderHex6(Rainbow.parse('hsl(120 100% 50%)')); // '#00ff00'

Color representations

| Type | Shape | Range | | ----------------- | ------------------- | ------------------ | | Color32 | packed 0xRRGGBBAA | each channel 0–255 | | ColorRGBAStruct | { r, g, b, a } | each channel 0–1 | | ColorHSLAStruct | { h, s, l, a } | each channel 0–1 |

Color32 is the currency of the library: every function takes or returns one. Struct channels are floating point, so conversions are accurate but not always exact — compare with a tolerance rather than ===.

API

Parsing

Rainbow.parse(css: string): Color32

Accepts:

  • hex — #RGB, #RGBA, #RRGGBB, #RRGGBBAA
  • rgb(r, g, b) / rgba(r, g, b, a), channels as 0–255 or percentages
  • hsl(h, s%, l%) / hsla(h, s%, l%, a), hue in deg, turn, rad or grad
  • CSS Level 4 space-and-slash syntax — rgb(255 0 0 / 0.5), hsl(120 100% 50% / 0.5)
  • all 148 CSS named colors — red, cornflowerblue, rebeccapurple, …

Throws on anything it cannot parse.

Conversion

| Function | Returns | | ---------------------------------- | ----------------- | | Rainbow.convertToRGBA(color) | ColorRGBAStruct | | Rainbow.convertToHSLA(color) | ColorHSLAStruct | | Rainbow.fromRGBA({ r, g, b, a }) | Color32 | | Rainbow.fromHSLA({ h, s, l, a }) | Color32 |

Rendering

| Function | Example output | | --------------------------- | ------------------------- | | Rainbow.renderHex6(color) | '#663399' | | Rainbow.renderHex3(color) | '#639' | | Rainbow.renderRGB(color) | 'rgb(102, 51, 153)' | | Rainbow.renderRGBA(color) | 'rgba(102, 51, 153, 1)' |

Hex and renderRGB discard alpha. renderHex3 rounds each channel to the nearest 4-bit nibble.

Gradients

// Blend two colors; t = 0 returns c1, t = 1 returns c2.
Rainbow.lerpColor(c1, c2, 0.5);

// Shorthand for lerpColor(c1, c2, 0.5).
Rainbow.getMedianColor(c1, c2);

// Blend across an ordered array; t is clamped to [0, 1].
Rainbow.multiLerpColor([black, red, white], 0.25);

// Build an indexed palette from stops. The result has (lastIndex + 1)
// entries, linearly interpolated between stops. The lowest stop must be 0.
const ramp = Rainbow.createPalette([
  [0, Rainbow.parse('black')],
  [128, Rainbow.parse('red')],
  [255, Rainbow.parse('white')],
]); // ramp.length === 256

Named colors

HTML_COLORS is the raw lookup table — lowercase name to opaque Color32.

import { HTML_COLORS } from '@laboralphy/rainbow';
HTML_COLORS.cornflowerblue; // 0x6495edff

Development

npm run build          # bundle ESM + CJS + .d.ts via tsup/esbuild
npm test               # run the vitest suite
npm run test:coverage  # run with coverage thresholds
npm run lint           # eslint (type-aware)
npm run format         # prettier --write
npm run typecheck      # tsc --noEmit
npm run check          # format:check + lint + typecheck + test

License

ISC © Raphaël Marandet