mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
20 lines
448 B
TypeScript
20 lines
448 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 };
|