Files
pterodactyl-panel/resources/scripts/lib/helpers.ts
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

19 lines
447 B
TypeScript

function hexToRgba(hex: string, alpha = 1): string {
// noinspection RegExpSimplifiable
if (!/#?([a-fA-F0-9]{2}){3}/.test(hex)) {
return hex;
}
// noinspection RegExpSimplifiable
const pairs = hex.match(/[a-fA-F0-9]{2}/g);
if (!pairs || pairs.length < 3) {
return hex;
}
const [r, g, b] = pairs.map((v) => parseInt(v, 16));
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
export { hexToRgba };