MCPcopy Create free account
hub / github.com/bernaferrari/FigmaToCode / rgbTo8hex

Function rgbTo8hex

packages/backend/src/common/color.ts:14–24  ·  view source on GitHub ↗
(color: RGB, alpha: number)

Source from the content-addressed store, hash-verified

12};
13
14export const rgbTo8hex = (color: RGB, alpha: number): string => {
15 // when color is RGBA, alpha is set automatically
16 // when color is RGB, alpha need to be set manually (default: 1.0)
17 const hex =
18 ((alpha * 255) | (1 << 8)).toString(16).slice(1) +
19 ((color.r * 255) | (1 << 8)).toString(16).slice(1) +
20 ((color.g * 255) | (1 << 8)).toString(16).slice(1) +
21 ((color.b * 255) | (1 << 8)).toString(16).slice(1);
22
23 return hex;
24};
25
26/**
27 * Converts RGB values to CSS hex or rgba format

Callers 3

flutterShadowFunction · 0.90
flutterColorFunction · 0.90
composeShadowFunction · 0.90

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected