UNPKG

@dvcol/common-utils

Version:

Typescript library for common utility functions and constants

21 lines (19 loc) 459 B
// lib/common/utils/color.utils.ts function rgbToHex({ r, g, b }) { return `#${[r, g, b].map((x) => { const hex = x.toString(16); return hex.length === 1 ? `0${hex}` : hex; }).join("")}`; } function hexToRgb(hex) { const cleanHex = hex.replace(/^#/, ""); const bigint = parseInt(cleanHex, 16); const r = bigint >> 16 & 255; const g = bigint >> 8 & 255; const b = bigint & 255; return { r, g, b }; } export { rgbToHex, hexToRgb };