Colors
The Colors module provides a comprehensive set of functions for manipulating and converting colors in different formats (HEX, RGB/RGBA, HSL/HSLA). With these functions, you can easily:
- Parse color strings to extract their components
- Convert between different color formats (HEX ↔ RGB ↔ HSL)
- Validate color strings in various formats
- Generate random colors
All functions are designed to be simple to use and return consistent results, properly handling alpha (transparency) values when applicable.
Overview
parseColor(color: string): ParsedColorParses a color string and returns an object with model, values, and alpha, or null.
hexToHsl(hex: string): stringConverts a hexadecimal color to HSL format.
hexToRgb(hex: string): stringConverts a hexadecimal color to RGB or RGBA format.
hslToHex(hsl: string): stringConverts an HSL/HSLA color to hexadecimal.
hslToRgb(hsl: string): stringConverts an HSL/HSLA color to RGB/RGBA.
isHexColor(hex: string): booleanChecks if a string represents a valid hexadecimal color.
isHslColor(hsl: string): booleanChecks if a string represents a valid HSL/HSLA color.
isRgbColor(rgb: string): booleanChecks if a string represents a valid RGB/RGBA color.
rgbToHex(rgb: string): stringConverts an RGB/RGBA color to hexadecimal.
rgbToHsl(rgb: string): stringConverts an RGB/RGBA color to HSL/HSLA.
randomColor(format?: "hex" | "rgb" | "hsl", alpha?: boolean): stringGenerates a random color in the specified format, with optional alpha channel.
