website/src/helpers/colors.ts
2024-04-03 14:27:48 +02:00

15 lines
324 B
TypeScript

// function to turn css rgb() strings to hex
export function rgbToHex(rgb: string) {
let hex = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
if (!hex) return rgb;
return (
"#" +
hex
.slice(1)
.map((x) => {
return ("0" + parseInt(x).toString(16)).slice(-2);
})
.join("")
);
}