( hex: string )
| 54 | }; |
| 55 | |
| 56 | export const hexToRGB = ( |
| 57 | hex: string |
| 58 | ): { red: number; green: number; blue: number } => { |
| 59 | let r = "0"; |
| 60 | let g = "0"; |
| 61 | let b = "0"; |
| 62 | |
| 63 | if (hex.length === 4) { |
| 64 | r = "0x" + hex[1] + hex[1]; |
| 65 | g = "0x" + hex[2] + hex[2]; |
| 66 | b = "0x" + hex[3] + hex[3]; |
| 67 | } else if (hex.length === 7) { |
| 68 | r = "0x" + hex[1] + hex[2]; |
| 69 | g = "0x" + hex[3] + hex[4]; |
| 70 | b = "0x" + hex[5] + hex[6]; |
| 71 | } |
| 72 | |
| 73 | return { |
| 74 | red: +r, |
| 75 | green: +g, |
| 76 | blue: +b, |
| 77 | }; |
| 78 | }; |
| 79 | |
| 80 | // Checks both rgb and hex colors for contrast and returns true if the color is in the dark spectrum |
| 81 | export const isDarkColor = (color: string): boolean => { |
nothing calls this directly
no outgoing calls
no test coverage detected