@ooneex/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 pleasant, named colors you can use for tags, avatars, charts, and other UI accents.
Installation
Add the package with Bun.Usage
UsehexToRgba 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.
SIMPLE_COLORS is a readonly tuple of hex codes, and SIMPLE_COLOR_NAMES maps each one to its label.
When to use it
- You need to apply a hex color with transparency in inline styles or canvas, e.g.
hexToRgba(hex, 0.2)for hover/background tints. - You want a small, consistent set of distinguishable colors for tags, categories, charts, or avatar backgrounds without hand-picking values.
- You need to safely validate and normalize user-supplied hex input (invalid values return
nullinstead of throwing). - You don’t need it if you only ever use static CSS colors or a design system that already provides token-based color utilities.