Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module.exports = hex => {
if (hex.charAt(0) === '#') {
hex = hex.substring(1);
}
if (hex.length !== 3 && hex.length !== 6) {
return false;
}
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
let red = parseInt(hex.substring(0, 2), 16);
let blue = parseInt(hex.substring(4, 6), 16);
let green = parseInt(hex.substring(2, 4), 16);
return { red, green, blue };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.