summaryrefslogtreecommitdiff
path: root/util/hexToRGBA.ts
blob: bacb601386be2e492629014060c3f6e5e15ff2d9 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
export function hexToRGBA(hex: string, opacity: number) {
  return (
    'rgba(' +
    (hex = hex.replace('#', ''))
      .match(new RegExp('(.{' + hex.length / 3 + '})', 'g'))!
      .map((l) => parseInt(hex.length % 2 ? l + l : l, 16))
      .concat(isFinite(opacity) ? opacity : 1)
      .join(',') +
    ')'
  )
}