(hex: string)
| 19 | }; |
| 20 | |
| 21 | export const hexToRgb = (hex: string) => { |
| 22 | hex = hex.replace(/^#/, ""); |
| 23 | |
| 24 | const hexValues: string[] = []; |
| 25 | if (hex.length === 3) { |
| 26 | hexValues.push(hex.charAt(0) + hex.charAt(0)); |
| 27 | hexValues.push(hex.charAt(1) + hex.charAt(1)); |
| 28 | hexValues.push(hex.charAt(2) + hex.charAt(2)); |
| 29 | } else { |
| 30 | hexValues.push(hex.charAt(0) + hex.charAt(1)); |
| 31 | hexValues.push(hex.charAt(2) + hex.charAt(3)); |
| 32 | hexValues.push(hex.charAt(4) + hex.charAt(5)); |
| 33 | } |
| 34 | return hexValues.map((str) => parseInt(str, 16)); |
| 35 | }; |
| 36 | |
| 37 | const channelToByte = (channel: number): number => |
| 38 | Math.max(0, Math.min(255, Math.round(channel * 255))); |
no test coverage detected