(value: string)
| 1 | export function normalizeHexColor(value: string) { |
| 2 | const trimmed = value.trim(); |
| 3 | if (trimmed.length === 0) return null; |
| 4 | |
| 5 | const raw = trimmed.startsWith("#") ? trimmed.slice(1) : trimmed; |
| 6 | if (!/^[\dA-F]+$/i.test(raw)) return null; |
| 7 | |
| 8 | if (raw.length === 3 || raw.length === 4) { |
| 9 | return `#${raw |
| 10 | .split("") |
| 11 | .map((char) => `${char}${char}`) |
| 12 | .join("") |
| 13 | .toUpperCase()}`; |
| 14 | } |
| 15 | |
| 16 | if (raw.length === 6 || raw.length === 8) { |
| 17 | return `#${raw.toUpperCase()}`; |
| 18 | } |
| 19 | |
| 20 | return null; |
| 21 | } |
| 22 | |
| 23 | export function getHexColorDigitCount(value: string) { |
| 24 | const trimmed = value.trim(); |
no outgoing calls
no test coverage detected