MCPcopy Index your code
hub / github.com/figma/plugin-samples / rgbToHex

Function rgbToHex

variables-import-export/code.js:189–202  ·  view source on GitHub ↗
({ r, g, b, a })

Source from the content-addressed store, hash-verified

187}
188
189function rgbToHex({ r, g, b, a }) {
190 if (a !== 1) {
191 return `rgba(${[r, g, b]
192 .map((n) => Math.round(n * 255))
193 .join(", ")}, ${a.toFixed(4)})`;
194 }
195 const toHex = (value) => {
196 const hex = Math.round(value * 255).toString(16);
197 return hex.length === 1 ? "0" + hex : hex;
198 };
199
200 const hex = [toHex(r), toHex(g), toHex(b)].join("");
201 return `#${hex}`;
202}
203
204function parseColor(color) {
205 color = color.trim();

Callers 1

processCollectionFunction · 0.70

Calls 1

toHexFunction · 0.70

Tested by

no test coverage detected