'use strict';

Number.isInteger = Number.isInteger || function(value) {
  return typeof value === "number" &&
    isFinite(value) &&
    Math.floor(value) === value;
};

(function(exports){

  exports.getColorGradient = function(hex, length) {
    if (hex == null || length == null) {
      return [];
    }
    if(!/^#([0-9a-f]{3}){1,2}$/.test(hex)) {
      return [];
    }
    if(!Number.isInteger(length)) {
      return [];
    }
    if(length < 1 || length > 5) {
      return [];
    }

    var colorGradient = [];
    for(var i = 0; i < length; i++) {
      colorGradient.push(hex);
    }
    return colorGradient;
  };

  function hexToRgb(hex) {
    var hex = hex.substring(1);    // strip #
    if(hex.length === 3) {
      hex = hex.concat(hex);
    }
    return {
      r: parseInt(hex.substr(0, 2), 16),
      g: parseInt(hex.substr(2, 2), 16),
      b: parseInt(hex.substr(4, 2), 16)
    }
  }

})(this.colorPalette = {});

@@ -903,16 +903,1548 @@
  %7D%0A  %7D%0A%0A
+  function rgbToHsv(red, green, blue) %7B%0A    red = red / 255;%0A    green = green / 255;%0A    blue = blue / 255;%0A%0A    var max = Math.max(red, green, blue);%0A    var min = Math.max(red, green, blue);%0A    var delta = max - min;%0A    var saturation = max == 0 ? 0 : delta / max;%0A    var hue = 0;%0A%0A    if (delta) %7B%0A      switch (max) %7B%0A        case red:%0A          hue = ((green - blue) / delta);%0A          break;%0A        case green:%0A          hue = 2 + (blue - red) / delta;%0A          break;%0A        case blue:%0A          hue = 4 + (red - green) / delta;%0A          break;%0A      %7D%0A%09%09%7D%0A%0A%09%09hue = 60 * hue %7C 0;%0A%09%09if (hue %3C 0) hue += 360;%0A%09%09saturation = (saturation * 100) %7C 0;%0A%09%09var value = (max * 100) %7C 0;%0A%0A    return %7B%0A      hue: hue,%0A      saturation: saturation,%0A      value: value%0A    %7D%0A  %7D%0A%0A  function hsvToRgb(hue, saturation, value) %7B%0A    saturation = saturation / 100;%0A    value = value / 100;%0A    var chroma = saturation * value;%0A    var h = hue / 60;%0A    var x = chroma * (1 - Math.abs(h %25 2 - 1));%0A    var m = value - chroma;%0A%0A    chroma = (chroma + m) * 255 %7C 0;%0A    x = (x + m) * 255 %7C 0;%0A    m = m * 255 %7C 0;%0A%0A    if (h %3E= 0 && h %3C 1) %7B%09return %7B red: chroma, green: x, blue: m%7D; %7D%0A%09%09if (h %3E= 1 && h %3C 2) %7B%09return %7B red: x, green: chroma, blue: m%7D; %7D%0A%09%09if (h %3E= 2 && h %3C 3) %7B%09return %7B red: m, green: chroma, blue: x%7D; %7D%0A%09%09if (h %3E= 3 && h %3C 4) %7B%09return %7B red: m, green: x, blue: chroma%7D; %7D%0A%09%09if (h %3E= 4 && h %3C 5) %7B%09return %7B red: x, green: m, blue: chroma%7D; %7D%0A%09%09if (h %3E= 5 && h %3C 6) %7B%09return %7B red: chroma, green: m, blue: x%7D; %7D%0A  %7D%0A%0A
 %7D)(this.

add format conversion functions