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

beer-color-rgb

v0.3.5

Published

Convert EBC or SRM beer color values to RGB/hex — A.J. de Lange spectral model, CSS-ready

Downloads

386

Readme

beer-color-rgb

Convert EBC (European Brewery Convention) or SRM (Standard Reference Method) beer color values to RGB hex codes with scientific accuracy. Zero dependencies, fully typed, and ultra-lightweight (~2kB bundle size).

npm Bundle Size Types Build Socket Badge Node.js License

Table of Contents

What is it

beer-color-rgb takes an EBC or SRM value and converts it to a precise RGB color. It uses the A.J. de Lange spectral model — a scientifically validated method based on light transmission analysis of 99 real beers — producing colorimetrically accurate results suitable for brewing apps, color pickers, and design systems.

One package to rule them all, One library to type them, One plugin to style them all, Or in the CLI compile them.

Choose how you want to integrate it into your workflow:

  • As a core TypeScript library for direct color conversion logic.
  • As a Tailwind CSS v4 plugin to auto-generate color utility classes.
  • As a CLI tool to generate static JSON/CSS color palettes.

→ Live demo

Getting Started

Prerequisites:

npm

Install

npm install beer-color-rgb

Usage

As a library

import { ebcToHex, ebcToRgb, ebcToRgbObject, srmToHex } from "beer-color-rgb";

// EBC
ebcToHex(20); // → "#b95900"
ebcToRgb(20); // → "rgb(185, 89, 0)"
ebcToRgbObject(20); // → { r: 185, g: 89, b: 0 }

// SRM
srmToHex(10); // → "#ba5b00"

// Custom optical path (cm)
ebcToHex(20, { lightPath: 3 }); // → "#d88900"

As a CLI

# Single EBC conversion
npx beer-color-rgb 20
# → #b95900

# Single SRM conversion
npx beer-color-rgb --srm 10
# → #ba5b00

# Batch CSS generation
npx beer-color-rgb generate --format css --unit ebc --output colors.css

# Batch JSON generation
npx beer-color-rgb generate --format json --unit srm --output colors.json

# Custom optical path
npx beer-color-rgb 20 --path 3
# → #d88900

As a Tailwind CSS plugin

Tailwind CSS v4 (Recommended):

@import "tailwindcss";
@plugin "beer-color-rgb/plugin";

/* Optional: configure via @theme */
@theme {
  --beer-light-path: 3; /* optical path in cm, default 5 */
  --beer-ebc-start: 1; /* EBC range start, default 1 */
  --beer-ebc-end: 20; /* EBC range end, default 80 */
  --beer-srm-start: 1; /* SRM range start, default 1 */
  --beer-srm-end: 15; /* SRM range end, default 40 */
}

Tailwind CSS v3 (Legacy):

// tailwind.config.ts
import { beerColorPlugin } from "beer-color-rgb/plugin";

export default {
  plugins: [beerColorPlugin()],
};

This generates utility classes for EBC 1–80 and SRM 1–40:

<div class="ebc-bg-20">...</div>
<div class="srm-bg-10">...</div>

<!-- Decimal values supported, though uncommon in practice -->
<div class="ebc-bg-[35.5]">...</div>

Plugin options (v3 JS config — all options available):

beerColorPlugin({
  ebcRange: [1, 80], // or false to disable
  srmRange: [1, 40], // or false to disable
  lightPath: 5, // optical path in cm (default: 5)
});

Note: Disabling a range entirely (false) is v3/JS-only. In v4, use @theme variables to restrict the range.

Project Structure

beer-color-rgb/
├── src/
│   ├── convert.ts          # Core conversion logic (A.J. de Lange spectral model)
│   ├── index.ts            # Public API exports
│   ├── cli.ts              # Command-line interface
│   └── plugin.ts           # Tailwind CSS plugin
├── tests/
│   ├── convert.test.ts
│   ├── index.test.ts
│   └── plugin.test.ts
├── package.json
├── tsconfig.json
└── CHANGELOG.md

Configuration

Environment variables

None required. The conversion uses fixed CIE 1931 colorimetric data and D65 illuminant (standard daylight).

API reference

EBC functions

ebcToHex(ebc: number, options?: ColorOptions): string
// → "#b95900"

ebcToRgb(ebc: number, options?: ColorOptions): string
// → "rgb(185, 89, 0)"

ebcToRgbObject(ebc: number, options?: ColorOptions): { r: number; g: number; b: number }
// → { r: 185, g: 89, b: 0 }

ebcToRgbArray(ebc: number, options?: ColorOptions): [number, number, number]
// → [185, 89, 0]

SRM functions (SRM × 1.97 = EBC internally)

srmToHex(srm: number, options?: ColorOptions): string
srmToRgb(srm: number, options?: ColorOptions): string
srmToRgbObject(srm: number, options?: ColorOptions): { r: number; g: number; b: number }
srmToRgbArray(srm: number, options?: ColorOptions): [number, number, number]

ColorOptions

type ColorOptions = {
  lightPath?: number; // Optical path in cm (default: 5.0)
};

| lightPath | Use case | | --------------- | ------------------------------------------------ | | 5.0 (default) | BJCP standard — typical glass viewed in daylight | | 3.0 | Aesthetic middle ground — richer apparent color | | 1.27 | ASBC/EBC laboratory measurement standard |

How it works

The A.J. de Lange spectral model reconstructs the light transmission spectrum for a given EBC value, then converts the result to sRGB using CIE 1931 colorimetry with D65 (6500K daylight) illumination.

Pipeline:

EBC → Spectral transmission T(λ) → XYZ tristimulus → sRGB linear → sRGB gamma correction → #RRGGBB

This approach is more accurate than polynomial or exponential approximations, especially for pale beers (EBC 1–20) and dark beers (EBC 50+).

References

License

MIT — see LICENSE file.