Skip to content

pantoken-root / design/swatches/src / hexToRgb

Function: hexToRgb() ​

hexToRgb(hex): Rgb | undefined

Experimental

Parse #rgb/#rrggbb/#rrggbbaa to 0–255 channels, or undefined if not a hex colour.

Parameters ​

hex ​

string

Returns ​

Rgb | undefined

Example ​

ts
import { hexToRgb } from "@pantoken/swatches";

hexToRgb("#ff8800"); // { r: 255, g: 136, b: 0 }
hexToRgb("nope"); // undefined