Skip to content

Instantly share code, notes, and snippets.

@kfox
Created January 11, 2018 18:48
Show Gist options
  • Save kfox/bf0d6fe6fd5499d817eb9f4f548f5d8f to your computer and use it in GitHub Desktop.
Save kfox/bf0d6fe6fd5499d817eb9f4f548f5d8f to your computer and use it in GitHub Desktop.
RGB/Hex Color Conversions in JavaScript
const convertRGBArrayToHexString = rgb =>
`#${rgb.map(color => ('0' + color.toString(16)).slice(-2)).join('')}`;
const convertHexStringToRGBArray = hex =>
hex.match(/[^#]{2}/g).map(color => parseInt(color, 16));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment