mirror of
https://github.com/KevinMidboe/infra-map.git
synced 2026-03-11 00:20:32 +00:00
linting
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
export function hexToRgba(hex: string, alpha = 1) {
|
||||
// Remove leading # if present
|
||||
hex = hex.replace(/^#/, '');
|
||||
// Remove leading # if present
|
||||
hex = hex.replace(/^#/, '');
|
||||
|
||||
// Handle shorthand (#fff → #ffffff)
|
||||
if (hex.length === 3) {
|
||||
hex = hex.split('').map(c => c + c).join('');
|
||||
}
|
||||
// Handle shorthand (#fff → #ffffff)
|
||||
if (hex.length === 3) {
|
||||
hex = hex
|
||||
.split('')
|
||||
.map((c) => c + c)
|
||||
.join('');
|
||||
}
|
||||
|
||||
if (hex.length !== 6) {
|
||||
throw new Error('Invalid HEX color.');
|
||||
}
|
||||
if (hex.length !== 6) {
|
||||
throw new Error('Invalid HEX color.');
|
||||
}
|
||||
|
||||
const r = parseInt(hex.substring(0, 2), 16);
|
||||
const g = parseInt(hex.substring(2, 4), 16);
|
||||
const b = parseInt(hex.substring(4, 6), 16);
|
||||
const r = parseInt(hex.substring(0, 2), 16);
|
||||
const g = parseInt(hex.substring(2, 4), 16);
|
||||
const b = parseInt(hex.substring(4, 6), 16);
|
||||
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user