Extract Color Values
Utility functions to extract numeric component values from CSS RGB/RGBA/HSL/HSLA color strings.
Overview
These utility functions extract numeric component values from CSS functional notation color strings, providing strict validation and typed tuples as returns.
extractSolidColorValues
Extracts numeric values from solid color strings (RGB or HSL formats).
Function Signature
function extractSolidColorValues(color: HSL | RGB): SolidValuesParameters
color(HSL | RGB): The CSS solid color string.
Return Value
SolidValues: A tuple of three numbers[val1, val2, val3](representing RGB components $0 \dots 255$ or HSL components as degree/percentages). If validation fails, returns[0, 0, 0].
Example Usage
playground.ts
extractAlphaColorValues
Extracts numeric values from colors that include an alpha channel (RGBA or HSLA formats).
Function Signature
function extractAlphaColorValues(color: HSLA | RGBA): AlphaValuesParameters
color(HSLA | RGBA): The CSS alpha-enabled color string.
Return Value
AlphaValues: A tuple of four numbers[val1, val2, val3, alpha]. If validation fails, returns[0, 0, 0, 0].
Example Usage
playground.ts
Type Definitions
type SolidValues = [number, number, number];
type AlphaValues = [number, number, number, number];See Also
- Color checkers - Form validation checks.
- Color class - OOP wrapper for color manipulation.
Last updated: Sun, Jun 14, 2026 07:15:25PM (UTC)
