Skip to content

Instantly share code, notes, and snippets.

@genert
Created June 30, 2015 14:00
Show Gist options
  • Save genert/c5f86f9b12480c213163 to your computer and use it in GitHub Desktop.
Save genert/c5f86f9b12480c213163 to your computer and use it in GitHub Desktop.
Simple ES6 based color class, that has 2 functions: rgbToHex and hexToRgb.
class Color {
rgbToHex (r, g, b) {
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
hexToRgb (hex) {
let arr = hex.slice(1).match(/.{1,2}/g);
return [parseInt(arr[0], 16), parseInt(arr[1], 16), parseInt(arr[2], 16)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment