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

normalize-colors

v0.0.1

Published

normalize colors

Downloads

2,353

Readme

normalize-colors

Normalize any CSS color value to a hex string (#RRGGBB). Supports hex, named colors, and all major CSS color functions and spaces.

Install

npm install normalize-colors
# or
npm i normalize-colors

Usage

const normalizeColor = require("normalize-colors");
// or
import normalizeColor from "normalize-colors";

normalizeColor("red");                    // "#FF0000"
normalizeColor("rgb(255, 0, 0)");        // "#FF0000"
normalizeColor("hsl(0 100% 50%)");        // "#FF0000"
normalizeColor("color(display-p3 1 0 0)"); // "#FF0000"

Returns #RRGGBB for valid colors, or #000000 for invalid/missing input. Alpha is ignored; output is always opaque hex.


Supported color formats

Hex

| Format | Example | |--------|--------| | 6-digit hex | #FF0000, #ff0000 | | 3-digit hex | #F00#FF0000 |

Named colors

All CSS named colors (e.g. red, aliceblue, rebeccapurple) and transparent (normalized to 0x00000000).

RGB / RGBA

| Syntax | Example | |--------|--------| | rgb(r g b) | rgb(255 0 0) | | rgb(r, g, b) | rgb(255, 0, 0) | | rgba(r, g, b, a) | rgba(255, 0, 0, 0.5) |

Values: 0–255 for r,g,b; alpha is ignored for output.

HSL / HSLA

| Syntax | Example | |--------|--------| | hsl(h s% l%) | hsl(120 100% 50%) | | hsl(h, s%, l%) | hsl(120, 100%, 50%) | | hsla(h, s%, l%, a) | hsla(120, 100%, 50%, 0.5) |

  • H: hue in degrees (0–360).
  • S: saturation, number or percentage (0–100).
  • L: lightness, number or percentage (0–100).
    Alpha is ignored.

HWB

| Syntax | Example | |--------|--------| | hwb(h w% b%) | hwb(120 50% 0%) | | hwb(h, w%, b%) | hwb(120, 50%, 0%) |

  • H: hue in degrees (0–360).
  • W: whiteness, number or percentage (0–100).
  • B: blackness, number or percentage (0–100).

LAB (CIE L*a*b*)

| Syntax | Example | |--------|--------| | lab(L a b) | lab(50 10 -5) | | lab(L% a b) | lab(50% 0 0) |

  • L: lightness (0–100 or 0%–100%).
  • a, b: opponent axes (unbounded in theory).

LCH (CIE LCH)

| Syntax | Example | |--------|--------| | lch(L C H) | lch(50% 20 180) | | lch(L, C, H) | lch(50, 20, 180) |

  • L: lightness (0–100 or percentage).
  • C: chroma (≥ 0).
  • H: hue in degrees (0–360).

OKLAB

| Syntax | Example | |--------|--------| | oklab(L a b) | oklab(0.6 0.1 -0.05) | | oklab(L% a b) | oklab(60% 0.1 -0.05) |

  • L: lightness (0–1 or 0%–100%).
  • a, b: opponent axes.

OKLCH

| Syntax | Example | |--------|--------| | oklch(L C H) | oklch(0.6 0.2 180) | | oklch(L%, C, H) | oklch(60% 0.2 180) |

  • L: lightness (0–1 or percentage).
  • C: chroma (≥ 0).
  • H: hue in degrees (0–360).

CSS color() function

All spaces defined in CSS Color Module Level 4 for color() are supported. Components are numbers in the range 0–1 or percentages; optional alpha after / is ignored.

| Space | Description | Example | |-------|-------------|--------| | srgb | sRGB (gamma-encoded) | color(srgb 0.5 0 0) | | srgb-linear | Linear sRGB | color(srgb-linear 0.215 0 0) | | display-p3 | Display P3 (D65) | color(display-p3 0.24 0.52 0.48) | | a98-rgb | Adobe RGB (1998) | color(a98-rgb 0.44 0.5 0.37) | | prophoto-rgb | ProPhoto RGB (D50) | color(prophoto-rgb 0.28 0.4 0.42) | | rec2020 | ITU-R BT.2020 | color(rec2020 0.42 0.48 0.36) | | xyz | CIE XYZ (D65) | color(xyz 0.2 0.15 0.6) | | xyz-d50 | CIE XYZ (D50) | color(xyz-d50 0.2 0.14 0.45) | | xyz-d65 | CIE XYZ (D65) | color(xyz-d65 0.22 0.15 0.59) |

Syntax: color(<space> <c1> <c2> <c3> [ / <alpha> ])
Components can be space- or comma-separated. Values can be numbers (0–1), percentages (0%–100%), or none (treated as 0).


Summary

  • Hex: 3/6-digit.
  • Named: All CSS color names + transparent.
  • Functions: rgb, rgba, hsl, hsla, hwb, lab, lch, oklab, oklch, and color(<space> ...) with all predefined RGB and XYZ spaces above.

All of these are normalized to a single opaque hex string for consistent use in code or further processing.