Last active
April 4, 2018 08:48
-
-
Save darkmavis1980/d705aa2886d6c692e36639e4ab177c96 to your computer and use it in GitHub Desktop.
HexToRGB in Javascript
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
// Converts any given HEX color to the relative RGB value | |
const HexToRGB = hex => hex.match(hex.length === 6 ? /.{2}/g : /.{1}/g).map(color => { | |
color = hex.length === 3 ? color + color : color; | |
return parseInt(color, 16); | |
}); | |
console.log(HexToRGB('FFA955')); //[ 255, 169, 85 ] | |
console.log(HexToRGB('000000')); //[ 0, 0, 0 ] | |
console.log(HexToRGB('F00')); //[ 255, 0, 0 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment