Skip to content

Instantly share code, notes, and snippets.

@dataday
Created August 24, 2017 12:53
Show Gist options
  • Save dataday/9642d47df516001fe840065c1c6d64ed to your computer and use it in GitHub Desktop.
Save dataday/9642d47df516001fe840065c1c6d64ed to your computer and use it in GitHub Desktop.
Converts HEX to RGBA
const hexToRGBA = (hex: string, opacity: number = 1) => {
hex = hex.replace('#', '')
let r = parseInt(hex.substring(0, 2), 16)
let g = parseInt(hex.substring(2, 4), 16)
let b = parseInt(hex.substring(4, 6), 16)
return 'rgba(' + r + ',' + g + ',' + b + ',' + opacity + ')'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment