mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-05-05 21:12:34 +02:00
20 lines
562 B
TypeScript
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;
|
|
};
|