mirror of
https://github.com/Elvanos/fantasia-archive.git
synced 2024-06-02 18:34:47 +12:00
21 lines
546 B
TypeScript
21 lines
546 B
TypeScript
export function rgbToHex (color: string) {
|
|
const colorStringRegexMatch = color.match(/\d+/g)
|
|
if (colorStringRegexMatch !== null) {
|
|
const colorString = colorStringRegexMatch.map(function (x) {
|
|
x = parseInt(x).toString(16)
|
|
return (x.length === 1) ? '0' + x : x
|
|
}).join('')
|
|
return '#' + colorString
|
|
}
|
|
return false
|
|
}
|
|
|
|
export function hexToRgb (hex: string) {
|
|
const bigint = parseInt(hex, 16)
|
|
const r = (bigint >> 16) & 255
|
|
const g = (bigint >> 8) & 255
|
|
const b = bigint & 255
|
|
|
|
return r + ',' + g + ',' + b
|
|
}
|