MCPcopy
hub / github.com/CapSoftware/Cap / normalizeHexColor

Function normalizeHexColor

apps/desktop/src/utils/hex-color.ts:1–21  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

1export 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
23export function getHexColorDigitCount(value: string) {
24 const trimmed = value.trim();

Callers 3

hex-color.test.tsFile · 0.90
normalizeOpaqueHexColorFunction · 0.85
hexToRgbFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected