Created
July 27, 2017 18:13
-
-
Save ahallora/4960522c4739523513f044190ef94325 to your computer and use it in GitHub Desktop.
Convert hex value to RGB value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hexToRGBA (hex, opacity = 1) { | |
const components = hex | |
.replace('#', '') | |
.match(/.{1,2}/g) | |
.map(hextet => parseInt(hextet, 16)) | |
.concat(opacity) | |
.join(', '); | |
return `rgba(${components})` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment