(hex)
| 1944 | } |
| 1945 | |
| 1946 | function hexToRgb(hex) { |
| 1947 | // Remove # if present |
| 1948 | hex = hex.replace(/^#/, ''); |
| 1949 | |
| 1950 | // Parse the hex value |
| 1951 | let r, g, b; |
| 1952 | if (hex.length === 3) { |
| 1953 | // Short format (#RGB) |
| 1954 | r = parseInt(hex.charAt(0) + hex.charAt(0), 16); |
| 1955 | g = parseInt(hex.charAt(1) + hex.charAt(1), 16); |
| 1956 | b = parseInt(hex.charAt(2) + hex.charAt(2), 16); |
| 1957 | } else if (hex.length === 6) { |
| 1958 | // Long format (#RRGGBB) |
| 1959 | r = parseInt(hex.substr(0, 2), 16); |
| 1960 | g = parseInt(hex.substr(2, 2), 16); |
| 1961 | b = parseInt(hex.substr(4, 2), 16); |
| 1962 | } else { |
| 1963 | return null; // Invalid format |
| 1964 | } |
| 1965 | |
| 1966 | return { r, g, b }; |
| 1967 | } |
| 1968 | |
| 1969 | function isLightColor(hex) { |
| 1970 | const rgb = hexToRgb(hex || "#000000"); |
no outgoing calls
no test coverage detected