Created
May 24, 2018 09:52
-
-
Save schabluk/a679f4935c65783b8049389ecc1f91dc to your computer and use it in GitHub Desktop.
HEX color to RGB with alpha
This file contains hidden or 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
const hexToRGB = (hex, alpha) => { | |
const r = parseInt(hex.slice(1, 3), 16) | |
const g = parseInt(hex.slice(3, 5), 16) | |
const b = parseInt(hex.slice(5, 7), 16) | |
if (alpha) return `rgba(${r}, ${g}, ${b}, ${alpha})` | |
return `rgb(${r}, ${g}, ${b})` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment