function toHex(color) {
  if (colorCache[color]) {
    return colorCache[color];
  }

  if (color[0] === '#') {
    if (color.length === 7) {
      return color;
    }

    var hex = color.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
      return '#' + r + r + g + g + b + b;
    }); // hex3 to hex6

    colorCache[color] = hex;
    return hex;
  } // rgb/rgba to hex


  var rst = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  rst.shift();
  rst = arr2hex(rst);
  colorCache[color] = rst;
  return rst;
}
/**
 * Returns a hexadecimal string representing this color in RGB space, such as #f7eaba.
 * @param  {String} color color value
 * @return {String} Returns a hexadecimal string
 */
Returns a hexadecimal string representing this color in RGB space, such as #f7eaba.
@param  {String} color color value
@return {String} Returns a hexadecimal string
Returns a hexadecimal string representing this color in RGB space such as #f7eaba . @param { String } color color value @return { String } Returns a hexadecimal string
function toHex(color) {
  if (colorCache[color]) {
    return colorCache[color];
  }
  if (color[0] === '#') {
    if (color.length === 7) {
      return color;
    }
    var hex = color.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
      return '#' + r + r + g + g + b + b;
    }); 
    colorCache[color] = hex;
    return hex;
  } 
  var rst = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  rst.shift();
  rst = arr2hex(rst);
  colorCache[color] = rst;
  return rst;
}
function toHex ( color ) { if ( colorCache [ color ] ) { return colorCache [ color ] ; } if ( color [ 0 ] === '#' ) { if ( color . length === 7 ) { return color ; } var hex = color . replace ( / ^#?([a-f\d])([a-f\d])([a-f\d])$ / i , function ( m , r , g , b ) { return '#' + r + r + g + g + b + b ; } ) ; colorCache [ color ] = hex ; return hex ; } var rst = color . match ( / ^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]? / i ) ; rst . shift ( ) ; rst = arr2hex ( rst ) ; colorCache [ color ] = rst ; return rst ; }
Returns a hexadecimal string representing this color in RGB space, such as #f7eaba.
Returns a hexadecimal string representing this color in RGB space such as #f7eaba .
// hex3 to hex6 // rgb/rgba to hex