Created
May 11, 2015 20:16
-
-
Save bendc/ecd2a7e684677c308549 to your computer and use it in GitHub Desktop.
Hexadecimal to RGB converter
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
const toRGB = (() => { | |
const expand = hex => | |
hex.length < 7 ? hex.split("").reduce((a, b) => a + b + b) : hex; | |
const convert = hex => | |
hex.match(/[\d\w]{2}/g).map(val => parseInt(val, 16)); | |
return hex => { | |
const [r, g, b] = convert(expand(hex)); | |
return `rgb(${r}, ${g}, ${b})`; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: