Skip to content

Instantly share code, notes, and snippets.

@fsschmitt
Created August 22, 2016 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsschmitt/14f5bd44ddad9f39e714576205f2b664 to your computer and use it in GitHub Desktop.
Save fsschmitt/14f5bd44ddad9f39e714576205f2b664 to your computer and use it in GitHub Desktop.
const componentToHex = c => {
const hex = c.toString(16)
return hex.length === 1 ? '0' + hex : hex
}
const rgbToHex = (r, g, b) => '#' + [r, g, b].map(componentToHex).join('')
const hexToRgb = hex => hex.substring(1).match(/.{2}/g).map(x => parseInt(x, 16))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment