Created
December 22, 2018 20:23
-
-
Save NicholasKuchiniski/58b70cb530de005eec6bf588db8bee3c to your computer and use it in GitHub Desktop.
Transforma uma cor HEX para RGB OU RGBA
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
function hexToRgb(hex, transparency) { | |
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); | |
const r = parseInt(result[1], 16); | |
const g = parseInt(result[2], 16); | |
const b = parseInt(result[3], 16); | |
return transparency ? `rgba(${r}, ${g}, ${b}, ${transparency})` : `rgb(${r}, ${g}, ${b})` | |
} | |
export default hexToRgb; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usa o polished, tem muitas utils bacanas https://polished.js.org/docs/