MCPcopy Create free account
hub / github.com/bytebase/bytebase / hexToRgb

Function hexToRgb

frontend/src/utils/css.ts:21–35  ·  view source on GitHub ↗
(hex: string)

Source from the content-addressed store, hash-verified

19};
20
21export const hexToRgb = (hex: string) => {
22 hex = hex.replace(/^#/, "");
23
24 const hexValues: string[] = [];
25 if (hex.length === 3) {
26 hexValues.push(hex.charAt(0) + hex.charAt(0));
27 hexValues.push(hex.charAt(1) + hex.charAt(1));
28 hexValues.push(hex.charAt(2) + hex.charAt(2));
29 } else {
30 hexValues.push(hex.charAt(0) + hex.charAt(1));
31 hexValues.push(hex.charAt(2) + hex.charAt(3));
32 hexValues.push(hex.charAt(4) + hex.charAt(5));
33 }
34 return hexValues.map((str) => parseInt(str, 16));
35};
36
37const channelToByte = (channel: number): number =>
38 Math.max(0, Math.min(255, Math.round(channel * 255)));

Callers 8

TabButtonFunction · 0.90
EnvironmentLabelFunction · 0.90
TabItemFunction · 0.90
DatabaseDetailHeaderFunction · 0.90
EnvironmentNameFunction · 0.90
EnvironmentNameFunction · 0.90
hexToColorFunction · 0.70

Calls 1

parseIntFunction · 0.85

Tested by

no test coverage detected