You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
450 B

4 years ago
  1. function shortenRgb(red, green, blue) {
  2. var normalizedRed = Math.max(0, Math.min(parseInt(red), 255));
  3. var normalizedGreen = Math.max(0, Math.min(parseInt(green), 255));
  4. var normalizedBlue = Math.max(0, Math.min(parseInt(blue), 255));
  5. // Credit: Asen http://jsbin.com/UPUmaGOc/2/edit?js,console
  6. return '#' + ('00000' + (normalizedRed << 16 | normalizedGreen << 8 | normalizedBlue).toString(16)).slice(-6);
  7. }
  8. module.exports = shortenRgb;