Files
vscode-front-matter/src/dashboardWebView/utils/opacityColor.ts
Elio Struyf 35a6c8bada Tab colors
2024-04-01 17:06:48 +02:00

20 lines
562 B
TypeScript

export const opacityColor = (color: string | undefined, opacity: number) => {
if (color) {
if (color.startsWith('#')) {
return `${color}${Math.round(opacity * 255)
.toString(16)
.padStart(2, '0')}`;
} else if (color.startsWith('rgba')) {
const splits = color.split(',');
splits.pop();
return `${splits.join(', ')}, ${opacity})`;
} else if (color.startsWith('rgb')) {
return `${color.replace('rgb', 'rgba').replace(')', `, ${opacity})`)}`;
} else {
return color;
}
}
return color;
};