15 lines
324 B
TypeScript
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("")
|
|
);
|
|
}
|