hexToRgb
Parse a hex string (#rgb, #rgba, #rrggbb, #rrggbbaa; the leading # is optional) to 8-bit sRGB. Alpha is returned as 0-1.
import { hexToRgb } from '@pbroom/color-kit';srgb.ts:162function hexToRgb(hex: string): Rgb;Parameters
- hex
string - Hex color string
Returns
Throws
- When
hexhas any other length or a non-hex digit
Example
import { hexToRgb } from '@pbroom/color-kit';
hexToRgb('#3b82f6'); // → { r: 59, g: 130, b: 246, alpha: 1 }
hexToRgb('f008'); // → ≈ { r: 255, g: 0, b: 0, alpha: 0.5333 }