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

@toolsbee/colora

v0.2.0

Published

Tiny modern CSS color parser & converter (OKLCH-first).

Readme

Colora

Colora is a tiny, modern CSS color parser and converter with first-class OKLCH support.

It focuses on:

  • correctness (CSS Color Level 4 friendly)
  • predictable normalization
  • perceptual color workflows using OKLCH

Early development. API may evolve, but breaking changes will follow semantic versioning.

Maintained by toolsbee.com · https://www.toolsbee.com


Install

npm install @toolsbee/colora


Quick Start

import { parseColor } from "@toolsbee/colora";

parseColor("#0ea5e9").toRgb();
// { r: 14, g: 165, b: 233, a: 1 }

parseColor("rgb(10 20 30 / 0.5)").toHex();
// "#0A141E80"

parseColor("oklch(62% 0.18 240 / 0.9)").toCss();
// "oklch(62% 0.18 240 / 0.9)"

parseColor("hsl(0 100% 50%)").toRgb();
// { r: 255, g: 0, b: 0, a: 1 }

parseColor("color(display-p3 1 0 0)").toHex();
// "#FF0000" (Clamped to sRGB)

Core API

Colora exposes a single entry point and a small set of conversion methods.

parseColor(input: string)

Parses any supported CSS color format and returns a Color object.

const color = parseColor("rgba(255, 0, 0, 0.25)");

Color methods

| Method | Description | Returns | | --------- | ----------------------------------- | ------------------------ | | toRgb() | Convert to sRGB with alpha | { r, g, b, a } | | toHex() | Convert to hex with alpha if needed | "#RRGGBB" or "#RRGGBBAA" | | toHsl() | Convert to HSL | { h, s, l, a } | | toP3() | Convert to Display P3 | { r, g, b, a } | | toOklch() | Convert to OKLCH (perceptual) | { l, c, h, a } | | toCss() | Normalized CSS output | formatted string |

All conversions are bidirectional and preserve alpha.


RGB and OKLCH Workflows

const base = parseColor("#0ea5e9").toOklch();

const darker = {
  ...base,
  l: base.l - 0.1
};

parseColor(
  `oklch(${darker.l * 100}% ${darker.c} ${darker.h})`
).toHex();

CSS Normalization

parseColor("rgb(10,20,30)").toCss();
// "rgb(10 20 30)"

parseColor("rgb(10 20 30 / .5000)").toCss();
// "rgb(10 20 30 / 0.5)"

Supported Formats

Hex

  • #rgb
  • #rgba
  • #rrggbb
  • #rrggbbaa

RGB and RGBA

  • rgb(1 2 3)
  • rgb(1 2 3 / 0.5)
  • rgb(1, 2, 3)
  • rgba(1, 2, 3, 0.5)

HSL and HSLA

  • hsl(0 100% 50%)
  • hsl(0, 100%, 50%)
  • hsla(0, 100%, 50%, 0.5)

Display P3

  • color(display-p3 1 0 0)
  • color(display-p3 1 0 0 / 0.5)

OKLCH

  • oklch(62% 0.18 240)
  • oklch(0.62 0.18 240)
  • oklch(62% 0.18 240 / 0.9)
  • Hue units supported: deg, rad, grad, turn

Note: Parsing is strictly spec-compliant. Percentages must use %. Alpha in modern syntax must use /.


Browser Usage

<!doctype html>
<html>
  <body>
    <pre id="out">Loading…</pre>

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

      const cHex  = parseColor("#0ea5e9");
      const cRgb  = parseColor("rgb(10 20 30 / 0.5)");
      const cHsl  = parseColor("hsl(0 100% 50%)");
      const cP3   = parseColor("color(display-p3 0 1 0)");
      const cOkl  = parseColor("oklch(62% 0.18 240 / 0.9)");

      document.getElementById("out").textContent = JSON.stringify(
        {
          // Hex input
          hex_to_rgb: cHex.toRgb(),
          hex_to_hsl: cHex.toHsl(),
          hex_to_p3:  cHex.toP3(),
          hex_to_oklch: cHex.toOklch(),

          // RGB normalization
          rgb_to_css: cRgb.toCss(),
          rgb_to_hex: cRgb.toHex(),

          // HSL Input
          hsl_to_rgb: cHsl.toRgb(),
          hsl_to_css: cHsl.toCss(),

          // P3 Input (Wide Gamut)
          p3_to_rgb: cP3.toRgb(),
          p3_raw:    cP3.toP3(),

          // OKLCH conversions
          oklch_to_css: cOkl.toCss(),
          oklch_to_hex: cOkl.toHex(),
          oklch_to_rgb: cOkl.toRgb(),
          oklch_roundtrip: cOkl.toOklch()
        },
        null,
        2
      );
    </script>
  </body>
</html>

When using ES modules locally, run a local server. ES modules do not work reliably via file URLs.


Error Handling

try {
  parseColor("not-a-color");
} catch (err) {
  console.error(err.message);
}

Design Goals

  • Small, dependency-free core
  • Modern CSS Color Level 4 syntax
  • Perceptual correctness via OKLCH
  • ESM and CJS support
  • CDN-friendly builds

License

MIT