MCPcopy Index your code
hub / github.com/simstudioai/sim / hexToRgb

Function hexToRgb

apps/sim/lib/colors/convert.ts:7–22  ·  view source on GitHub ↗
(hex: string)

Source from the content-addressed store, hash-verified

5
6/** Parse a hex color string (with or without `#`) into RGB components. */
7export function hexToRgb(hex: string): { r: number; g: number; b: number } {
8 const cleaned = hex.replace(/^#/, '')
9 if (cleaned.length !== 6 && cleaned.length !== 3) {
10 return { r: 0, g: 0, b: 0 }
11 }
12 const full =
13 cleaned.length === 3
14 ? cleaned[0] + cleaned[0] + cleaned[1] + cleaned[1] + cleaned[2] + cleaned[2]
15 : cleaned
16 const num = Number.parseInt(full, 16)
17 return {
18 r: (num >> 16) & 0xff,
19 g: (num >> 8) & 0xff,
20 b: num & 0xff,
21 }
22}
23
24/** Convert RGB components (0-255 each) to a 6-digit `#rrggbb` hex string. */
25export function rgbToHex(r: number, g: number, b: number): string {

Callers 15

applyTintFunction · 0.90
applyShadeFunction · 0.90
applyLumModFunction · 0.90
applyLumOffFunction · 0.90
applySatModFunction · 0.90
applyHueModFunction · 0.90
applyHueOffFunction · 0.90
applySatOffFunction · 0.90
parseCssColorToRgbFunction · 0.90
renderShapeFunction · 0.90
mergeRunPropsFunction · 0.90
applyDuotoneFilterFunction · 0.90

Calls 1

replaceMethod · 0.65

Tested by

no test coverage detected