Parse a colour CSS colour string and return a RGBA object.
NOTE: There is already a similar function built into React
Native -> check if that can be used instead!
776915
function parseColor(col) {
  let tmp;
  if (typeof col === 'string') {
    col = col.trim();
    if (col.slice(0,1) === '#') {
      if (col.length === 7) {
        return {
          r: parseInt('0x' + col.substr(1,2)),
          g: parseInt('0x' + col.substr(3,2)),
          b: parseInt('0x' + col.substr(5,2)),
          a: 1
        };
      } else if (col.length === 4) {
        return {
          r: Math.pow(parseInt('0x' + col.substr(1,1))+1,2)-1,
          g: Math.pow(parseInt('0x' + col.substr(2,1))+1,2)-1,
          b: Math.pow(parseInt('0x' + col.substr(3,1))+1,2)-1,
          a: 1
        };
      } else if (col.length === 9) {
        return {
          r: parseInt('0x' + col.substr(1,2)),
          g: parseInt('0x' + col.substr(3,2)),
          b: parseInt('0x' + col.substr(5,2)),
          a: parseInt('0x' + col.substr(7,2)) / 255
        };
      } else if (col.length === 5) {
        return {
          r: Math.pow(parseInt('0x' + col.substr(1,1))+1,2)-1,
          g: Math.pow(parseInt('0x' + col.substr(2,1))+1,2)-1,
          b: Math.pow(parseInt('0x' + col.substr(3,1))+1,2)-1,
          a: parseInt('0x' + col.substr(4,1)) / 15
        };
      }
    } else if (col.slice(0,4) === 'rgba') {
      tmp = col.substr(5).split(',');
      return {
        r: parseInt(tmp[0]),
        g: parseInt(tmp[1]),
        b: parseInt(tmp[2]),
        a: parseFloat(tmp[3])
      };
    } else if (col.slice(0,4) === 'hsla') {
      tmp = col.substr(5).split(',').slice(0,4);
      tmp[0] = tmp[0] / 359;
      tmp[1] = tmp[1].slice(0,-1) / 100;
      tmp[2] = tmp[2].slice(0,-2) / 100;
      tmp = hslaToRgba(...tmp);
      return {
        r: tmp[0],
        g: tmp[1],
        b: tmp[2],
        a: parseFloat(tmp[3])
      };
    } else if (col.slice(0,3) === 'rgb') {
      tmp = col.substr(4).split(',');
      return {
        r: parseInt(tmp[0]),
        g: parseInt(tmp[1]),
        b: parseInt(tmp[2]),
        a: 1
      };
    } else if (col.slice(0,3) === 'hsl') {
      tmp = col.substr(4).split(',').slice(0,3);
      tmp[0] = tmp[0] / 359;
      tmp[1] = tmp[1].slice(0,-1) / 100;
      tmp[2] = tmp[2].slice(0,-2) / 100;
      tmp = hslToRgb(...tmp);
      return {
        r: tmp[0],
        g: tmp[1],
        b: tmp[2],
        a: 1
      };
    } else if (col.slice(0,2) === '0x') {
      return {
          r: parseInt('0x' + col.substr(2,2)),
          g: parseInt('0x' + col.substr(4,2)),
          b: parseInt('0x' + col.substr(6,2)),
          a: parseInt('0x' + col.substr(8,2)) / 255
        };
    } else if (col === 'transparent') {
      return {
          r: 0,
          g: 0,
          b: 0,
          a: 0
        };
    } else if (colorNames.hasOwnProperty(col)) {
      return parseColor(colorNames[col]);
    }
  }
}
525664
def _parse_color(self, color):
        """"""
        # If column was specified, force a scheme
        # It could be that there is a column named 'blue' for example
        if isinstance(color, dict):
            if 'column' not in color:
                raise ValueError("Color must include a 'column' value")
            # get scheme if exists. if not, one will be chosen later if needed
            scheme = color.get('scheme')
            color = color['column']
            self.style_cols[color] = None
        elif (color and
              color[0] != '#' and
              color not in webcolors.CSS3_NAMES_TO_HEX):
            # color specified that is not a web color or hex value so its
            #  assumed to be a column name
            color = color
            self.style_cols[color] = None
            scheme = None
        else:
            # assume it's a color (hex, rgb(...),  or webcolor name)
            color = color
            scheme = None

        return color, scheme
1243376
function getColorStr(color) {
    var hex = color.hexString();
    var alpha = getAlphaHex(color.alpha());
    var colorStr = '#' + alpha + hex.slice(1);

    return colorStr.toLowerCase();
}
1344209
function getColors(rawData) {

    // Regular expression matching colors variables naming pattern
    var REGEX = /^dc-(.*?)[0-9]+$/;

    var content = rawData
        .filter((item) => {
            var group = item.group[0];
            return group === 'colors'
                && item.context.type === 'variable'
                && item.context.name.match(REGEX);
        })
        .map((item) => {
            // extract color name (eg. `dc-magenta10 -> magenta`)
            item.color = item.context.name.replace(REGEX, '$1');
            item.color = _.capitalize(item.color);
            return item;
        });

    // transform colors array in a object, shaped as the view layer expect
    content = _.groupBy(content, (c) => c.color );
    Object.keys(content).forEach((color) => {
        content[color] = content[color].reduce((acc, c) => {
            acc['$' + c.context.name] = c.context.value;
            return acc;
        }, {});
    });
    return content;
}
1152415
def color_string(color, string):
    
    if not color_available:
        return string

    return color + string + colorama.Fore.RESET
478304
function parseRgb(rgbString) {
  const rgbRegex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/;
  const match = rgbRegex.exec(rgbString);
  if (match) {
    const r = match[1];
    const g = match[2];
    const b = match[3];
    return { r, g, b };
  } else {
    return null;
  }
}
1209120
function to_object(rgb){
    return {
        R: parseInt( rgb.substring(0, 2), 16),
        G: parseInt( rgb.substring(2, 4), 16),
        B: parseInt( rgb.substring(4), 16)
    };
}
521836
function findBackgroundColor(element) {
  if (element == null || typeof element.style === 'undefined') {
    // This element has no background, assume white.
    return 'rgb(255,255,255)';
  }
  const backgroundColor = getComputedStyle(element).backgroundColor;
  if (backgroundColor === 'transparent' || backgroundColor === 'rgba(0, 0, 0, 0)') {
    return findBackgroundColor(element.parentNode);
  } else {
    return backgroundColor;
  }
}
36459
function _retrieveColor(palette, color, hue = '500', format) {
    if (typeof palette !== 'string' || typeof color !== 'string' || typeof hue !== 'string' || typeof format !== 'string') {
        throw new TypeError('Expected a string');
    }

    let hexColor;
    let result;

    try {
        hexColor = (palette === 'md') ? colors[palette][color][hue].hex : colors[palette][color];

        switch (format) {
            case 'rgb':
                result = _toRGB(hexColor);
                result = `rgb(${result.r}, ${result.g}, ${result.b})`;
                break;
            case 'hex':
                result = `#${hexColor}`;
                break;
            case 'raw':
                result = _toRGB(hexColor);
                result.hex = hexColor;
                break;
            default:
        }
    } catch (err) {
        throw new RangeError('No matching color.');
    }
    return result;
}
770139
function ( color, parse ) {
            var type = this.type( color, 'color.toRgb() : "' + color + '" ' + MSG_NOT_COLOR ),
                objColor;
    
            switch ( type ) {
                case 'rgb':
                    return parse? this.parseRgba( color ) : color;
                    break;
                case 'rgba':
                    objColor = this.parseRgba( color );
                    break;
                case 'hsl':
                case 'hsla':
                    objColor = this.hslToRgb( color, true );
                    break;
                case 'keyword':
                    color = this.keyword( color, 'color.toRgb() : "' + color + '" ' + MSG_NOT_COLOR );
                case 'hex':
                    objColor = this.hexToRgb( color, true );
                    break;
            }
    
            return parse? objColor : 'rgb(' + objColor.r + ', ' + objColor.g + ', ' + objColor.b + ')';
        }
1303381
function Color(value) {
    this.r = 0;
    this.g = 0;
    this.b = 0;
    this.a = null;
    var result = this.fromArray(value) ||
        this.namedColor(value) ||
        this.rgb(value) ||
        this.rgba(value) ||
        this.hex6(value) ||
        this.hex3(value);
}
723332
function extractRgbValues(rgbString) {
  const rgbRegex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d\.]+\s*)?\)/;
  const match = rgbRegex.exec(rgbString);
  if (match) {
    return {
      r: parseInt(match[1]),
      g: parseInt(match[2]),
      b: parseInt(match[3])
    };
  } else {
    return null;
  }
}
212781
def _get_color(color):
        
        color = str(color).replace("#", "")
        qcolor = QtGui.QColor()
        qcolor.setRgb(int(color[:2], base=16),
                      int(color[2:4], base=16),
                      int(color[4:6], base=16))
        return qcolor
716432
function parseColor (str) {
    if (str.substr(0,1) === '#') {
      // Handle color shorthands (like #abc)
      var shorthand = str.length === 4,
          m = str.match(shorthand ? /\w/g : /\w{2}/g);

      if (!m) return;
      m = m.map(function(s) { return parseInt(shorthand ? s+s : s, 16) });
      return new nodes.RGBA(m[0],m[1],m[2],1);
    }
    else if (str.substr(0,3) === 'rgb'){
      var m = str.match(/([0-9]*\.?[0-9]+)/g);
      if (!m) return;
      m = m.map(function(s){return parseFloat(s, 10)});
      return new nodes.RGBA(m[0], m[1], m[2], m[3] || 1);
    }
    else {
      var rgb = colors[str];
      if (!rgb) return;
      return new nodes.RGBA(rgb[0], rgb[1], rgb[2], 1);
    }
  }
501647
def convert_color(color):
    
    if color is not None:

        # is the color a string
        if isinstance(color, str):
            # strip the color of white space
            color = color.strip()

            # if it starts with a # check it is a valid color
            if color[0] == "#":

                # check its format
                if len(color) != 7:
                    raise ValueError("{} is not a valid # color, it must be in the format #ffffff.".format(color))
                else:
                    # split the color into its hex values
                    hex_colors = (color[1:3], color[3:5], color[5:7])

                    # check hex values are between 00 and ff
                    for hex_color in hex_colors:
                        try:
                            int_color = int(hex_color, 16)
                        except:
                            raise ValueError("{} is not a valid value, it must be hex 00 - ff".format(hex_color))

                        if not (0 <= int_color <= 255):
                            raise ValueError("{} is not a valid color value, it must be 00 - ff".format(hex_color))

        # if the color is not a string, try and convert it
        else:
            # get the number of colors and check it is iterable
            try:
                no_of_colors = len(color)
            except:
                raise ValueError("A color must be a list or tuple of 3 values (red, green, blue)")

            if no_of_colors != 3:
                raise ValueError("A color must contain 3 values (red, green, blue)")

            # check the color values are between 0 and 255
            for c in color:
                if not (0 <= c <= 255):
                    raise ValueError("{} is not a valid color value, it must be 0 - 255")

            # convert to #ffffff format
            color = "#{:02x}{:02x}{:02x}".format(color[0], color[1], color[2])

    return color
882462
function (colour) {
  if (!colour || !!((colour = String(colour)).indexOf("-") + 1)) {
    return {r: -1, g: -1, b: -1, opacity: -1, error: 1};
  }
  if (colour == "none") {
    return {r: -1, g: -1, b: -1, opacity: -1};
  }
  !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  if (!colour) {
    return {r: -1, g: -1, b: -1, opacity: -1, error: 1};
  }
  var res,
      red,
      green,
      blue,
      opacity,
      t,
      values,
      rgb = colour.match(colourRegExp);
  if (rgb) {
    if (rgb[2]) {
      blue = parseInt(rgb[2].substring(5), 16);
      green = parseInt(rgb[2].substring(3, 5), 16);
      red = parseInt(rgb[2].substring(1, 3), 16);
    }
    if (rgb[3]) {
      blue = parseInt((t = rgb[3].charAt(3)) + t, 16);
      green = parseInt((t = rgb[3].charAt(2)) + t, 16);
      red = parseInt((t = rgb[3].charAt(1)) + t, 16);
    }
    if (rgb[4]) {
      values = rgb[4].split(commaSpaces);
      red = parseFloat(values[0]);
      values[0].slice(-1) == "%" && (red *= 2.55);
      green = parseFloat(values[1]);
      values[1].slice(-1) == "%" && (green *= 2.55);
      blue = parseFloat(values[2]);
      values[2].slice(-1) == "%" && (blue *= 2.55);
      rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = parseFloat(values[3]));
      values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
    }
    if (rgb[5]) {
      values = rgb[5].split(commaSpaces);
      red = parseFloat(values[0]);
      values[0].slice(-1) == "%" && (red /= 100);
      green = parseFloat(values[1]);
      values[1].slice(-1) == "%" && (green /= 100);
      blue = parseFloat(values[2]);
      values[2].slice(-1) == "%" && (blue /= 100);
      (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
      rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = parseFloat(values[3]));
      values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
      return hsb2rgb(red, green, blue, opacity);
    }
    if (rgb[6]) {
      values = rgb[6].split(commaSpaces);
      red = parseFloat(values[0]);
      values[0].slice(-1) == "%" && (red /= 100);
      green = parseFloat(values[1]);
      values[1].slice(-1) == "%" && (green /= 100);
      blue = parseFloat(values[2]);
      values[2].slice(-1) == "%" && (blue /= 100);
      (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
      rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = parseFloat(values[3]));
      values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
      return hsl2rgb(red, green, blue, opacity);
    }
    red = Math.min(Math.round(red), 255);
    green = Math.min(Math.round(green), 255);
    blue = Math.min(Math.round(blue), 255);
    opacity = Math.min(Math.max(opacity, 0), 1);
    rgb = {r: red, g: green, b: blue};
    rgb.opacity = isFinite(opacity) ? opacity : 1;
    return rgb;
  }
  return {r: -1, g: -1, b: -1, opacity: -1, error: 1};
}
1063440
function convertColorComponent (input) {
  let result = input.toString(16);
  if (result.length < 2) {
    result = '0' + result
  }
  return result;
}