MCPcopy Create free account
hub / github.com/codesandbox/sandpack / hexToRGB

Function hexToRGB

sandpack-react/src/utils/stringUtils.ts:56–78  ·  view source on GitHub ↗
(
  hex: string
)

Source from the content-addressed store, hash-verified

54};
55
56export 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
81export const isDarkColor = (color: string): boolean => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected