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

hex-color-token-kit

v0.1.1

Published

Extract and validate CSS hex color tokens with spans and diagnostics.

Readme

hex-color-token-kit

npm version License: MPL-2.0 CI

Small TypeScript utility for extracting and validating CSS hex color tokens.

It focuses on one job: find #rgb, #rgba, #rrggbb, and #rrggbbaa tokens in text, return source spans, normalize them, and explain malformed candidates without requiring Node APIs.

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package marked as side-effect free for bundlers.
  • CI runs npm ci, typecheck, build, and test.
  • Tested on Node.js 20 and 22 with GitHub Actions.

Demo

Try the interactive demo

Install

npm install hex-color-token-kit

Usage

import {
  extractHexColorTokens,
  isHexColorToken,
  parseHexColorToken
} from "hex-color-token-kit";

const tokens = extractHexColorTokens("color: #0f38; border: #336699;");

tokens.valid.map((token) => token.normalized);
// ["#00ff3388", "#336699"]

tokens.invalid;
// []

parseHexColorToken("#abc");
// { ok: true, value: { input: "#abc", normalized: "#aabbcc", channels: { r: 170, g: 187, b: 204 }, ... } }

isHexColorToken("#336699");
// true

API

parseHexColorToken(input, options?)

Validates one token. It returns a discriminated union instead of throwing. Non-string runtime input returns a not_a_string diagnostic.

const result = parseHexColorToken("#ff8800", {
  allowAlpha: true,
  requireHash: true
});

extractHexColorTokens(input, options?)

Scans text and returns valid and invalid token-like candidates with offsets. Non-string source text returns an empty result with a not_a_string diagnostic.

const result = extractHexColorTokens("ok #fff bad #12zzzz", {
  includeInvalid: true
});

isHexColorToken(input, options?)

Returns true when a single token is valid. Use it for lightweight checks when you do not need channels, normalized values, or diagnostics.

Options

  • allowAlpha: accept 4-digit and 8-digit alpha forms. Defaults to true.
  • requireHash: require a leading #. Defaults to true.
  • normalize: return expanded lowercase hex values. Defaults to true.
  • includeInvalid: include malformed candidates found while scanning. Defaults to true.
  • maxInputLength: guard scanning work. Defaults to 100_000.

Invalid maxInputLength values are ignored with an invalid_options diagnostic.

When requireHash is false, extraction also considers standalone 3-8 digit hex-like words. Keep the default for CSS text and enable loose matching only for inputs where bare color tokens are expected.

Browser compatibility

The core uses only strings, arrays, regular expressions, and numbers. It has no runtime dependencies and no required Node APIs.

CLI

No CLI is included. The natural use is as a small parser inside CSS tooling, design-token checks, forms, and browser UIs; a CLI would add Node-only packaging without clear value for the core use case.

License

MPL-2.0