mirror of
https://github.com/theoludwig/p61-project.git
synced 2024-07-17 07:00:12 +02:00
19 lines
496 B
TypeScript
19 lines
496 B
TypeScript
|
export const colorsPresenter = {
|
||
|
hexToRgbA: (hexColor: string, opacity: number): string => {
|
||
|
let hex = hexColor.replace("#", "")
|
||
|
if (hex.length === 3) {
|
||
|
hex = hex
|
||
|
.split("")
|
||
|
.map((char) => {
|
||
|
return char + char
|
||
|
})
|
||
|
.join("")
|
||
|
}
|
||
|
const color = Number.parseInt(hex, 16)
|
||
|
const red = (color >> 16) & 255
|
||
|
const green = (color >> 8) & 255
|
||
|
const blue = color & 255
|
||
|
return `rgba(${red}, ${green}, ${blue}, ${opacity})`
|
||
|
},
|
||
|
}
|