Skip to content

Instantly share code, notes, and snippets.

@NicholasKuchiniski
Created December 22, 2018 20:23
Show Gist options
  • Save NicholasKuchiniski/58b70cb530de005eec6bf588db8bee3c to your computer and use it in GitHub Desktop.
Save NicholasKuchiniski/58b70cb530de005eec6bf588db8bee3c to your computer and use it in GitHub Desktop.
Transforma uma cor HEX para RGB OU RGBA
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;
@vitordino
Copy link

usa o polished, tem muitas utils bacanas https://polished.js.org/docs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment