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

color-alchemy

v1.0.0

Published

A comprehensive color manipulation utility library.

Downloads

91

Readme

ColorAlchemy

A robust, dependency-free JavaScript library for color manipulation, conversion, and accessibility analysis.

Features

  • Universal Parsing: Handles Hex (#FFF, #FFFFFF), RGB strings (rgb(255, 0, 0)), HSL strings (hsl(0, 100%, 50%)), and Objects ({r: 255, g: 0, b:0}).
  • Conversions: Convert seamlessly between RGB, Hex, HSL, HSV, and CMYK.
  • Manipulation: Lighten, Darken, Saturate, Desaturate, Rotate Hue, and set Alpha transparency.
  • Accessibility: Built-in WCAG contrast ratio calculations and AA/AAA compliance checks.
  • Palette Generation: Automatically generate Complementary, Analogous, Triadic, Tetradic, and Split-Complementary color harmonies.

Installation

npm install color-alchemy

Real-World Use Case: Automated Theme Generation

One of the most powerful features is the ability to generate entire design systems from a single brand color. The library can automatically create interactive states (hover/active) and ensure text accessibility.

import { Color } from 'color-alchemy';

function generateTheme(brandHex) {
  const primary = new Color(brandHex);
  const white = new Color('#ffffff');
  const black = new Color('#000000');

  // Automatically determine if white or black text is more readable
  const textColor = primary.contrast(white) >= 4.5 ? '#ffffff' : '#000000';

  return {
    brand: primary.toHex(),
    // Generate consistent hover/active states mathmatically
    hover: primary.clone().lighten(10).toHex(),
    active: primary.clone().darken(10).toHex(),
    // Accessible text color
    textOnPrimary: textColor,
    // Generate a harmonious accent color
    accent: primary.complementary()[0].toHex()
  };
}

const myTheme = generateTheme('#6b2c91');
console.log(myTheme);
/*
Output:
{
  brand: "#6b2c91",
  hover: "#8738b7",
  active: "#4d2069",
  textOnPrimary: "#ffffff",
  accent: "#53902c"
}
*/

API Reference

Constructor

new Color(input)

Creates a new color instance.

  • input: string (Hex, RGB, HSL) or object ({r, g, b, a}).
  • Example: new Color('#ff0000') or new Color('rgb(255, 0, 0)').

Conversion Methods

| Method | Description | Return Format | |--------|-------------|---------------| | toHex() | Returns the Hex representation. | "#ff0000" | | toRgb() | Returns the RGB object. | { r: 255, g: 0, b: 0, a: 1 } | | toHsl() | Returns the HSL object. | { h: 0, s: 100, l: 50, a: 1 } | | toHsv() | Returns the HSV object. | { h: 0, s: 100, v: 100, a: 1 } | | toCmyk() | Returns the CMYK object. | { c: 0, m: 100, y: 100, k: 0 } |

Manipulation Methods

All manipulation methods return the Color instance itself (chainable), except those that return palettes.

  • lighten(amount): Lightens the color by a percentage (0-100).
  • darken(amount): Darkens the color by a percentage (0-100).
  • saturate(amount): Increases saturation by a percentage (0-100).
  • desaturate(amount): Decreases saturation by a percentage (0-100).
  • rotate(degrees): Rotates the hue by degrees (0-360).
  • setAlpha(value): Sets the alpha transparency (0-1).
  • clone(): Returns a new new independent instance of the current color.

Accessibility Tools

  • getLuminance(): Returns the relative luminance (0 to 1).
  • contrast(otherColor): Returns the contrast ratio between this color and another (1 to 21).
    • Example: color.contrast(new Color('#fff'))
  • isAccessible(otherColor, level, size): Returns true if the contrast meets WCAG standards.
    • level: 'AA' (default) or 'AAA'.
    • size: 'small' (default) or 'large'.

Palette Generation

These methods return an Array of new Color instances.

  • complementary(): Returns 1 color (180° rotation).
  • analogous(): Returns 2 colors (-30° and +30°).
  • triadic(): Returns 2 colors (120° and 240°).
  • tetradic(): Returns 3 colors (90°, 180°, 270°).
  • splitComplementary(): Returns 2 colors (150° and 210°).

License

ISC