(hex: string)
| 1 | type RgbColor = { r: number; g: number; b: number }; |
| 2 | |
| 3 | function hexToRgb(hex: string): null | RgbColor { |
| 4 | const matches = hex.match(/^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i); |
| 5 | |
| 6 | if (!matches) { |
| 7 | return null; |
| 8 | } |
| 9 | |
| 10 | return { |
| 11 | r: parseInt(matches[1], 16), |
| 12 | g: parseInt(matches[2], 16), |
| 13 | b: parseInt(matches[3], 16), |
| 14 | }; |
| 15 | } |
| 16 | |
| 17 | function rgbToHex(rgb: RgbColor): string { |
| 18 | const hex = Object.values(rgb) |
no test coverage detected