* Converts hex color to RGB
(hex: string)
| 2 | * Converts hex color to RGB |
| 3 | */ |
| 4 | function hexToRgb(hex: string): { r: number; g: number; b: number } | null { |
| 5 | const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); |
| 6 | return result |
| 7 | ? { |
| 8 | r: parseInt(result[1], 16), |
| 9 | g: parseInt(result[2], 16), |
| 10 | b: parseInt(result[3], 16), |
| 11 | } |
| 12 | : null; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Converts RGB to HSL |