(hex: HexColor)
| 9 | } |
| 10 | |
| 11 | export function hexToRgb(hex: HexColor): { r: number; g: number; b: number } { |
| 12 | const h = hex.replace("#", "") |
| 13 | const full = |
| 14 | h.length === 3 || h.length === 4 |
| 15 | ? h |
| 16 | .split("") |
| 17 | .map((c) => c + c) |
| 18 | .join("") |
| 19 | : h |
| 20 | const rgb = full.length === 8 ? full.slice(0, 6) : full |
| 21 | |
| 22 | const num = parseInt(rgb, 16) |
| 23 | return { |
| 24 | r: ((num >> 16) & 255) / 255, |
| 25 | g: ((num >> 8) & 255) / 255, |
| 26 | b: (num & 255) / 255, |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | export function rgbToHex(r: number, g: number, b: number): HexColor { |
| 31 | const toHex = (v: number) => { |
no outgoing calls
no test coverage detected