Skip to main content
@talosjs/color is a tiny color helper for the browser and server. It converts hex color codes into CSS rgba() strings, with optional alpha, and ships a fixed palette of named colors for tags, avatars, charts, and other UI accents.

Installation

Add the package with Bun.

Usage

Use hexToRgba to turn any hex code into an rgba() string. It accepts 3, 4, 6, or 8 digit hex (with or without a leading #) and returns null when the input is invalid.
The package also exports a curated palette and a map of human-readable names. SIMPLE_COLORS is a readonly tuple of hex codes, and SIMPLE_COLOR_NAMES maps each one to its label.

Where it fits

The two jobs this covers are applying transparency to a hex color (hexToRgba(hex, 0.2) for a hover or background tint, whether in inline styles or on a canvas) and assigning colors from a fixed set without hand-picking values for every tag, category, or avatar. Because invalid input returns null rather than throwing, it also works as a validator for user-supplied hex strings. If you only ever use static CSS colors, or a design system already hands you token-based color utilities, you won’t need this.