lib/colorUtils.js
function convertColorToRGBA(color) {
  const cstr = `${color}`.toLowerCase().trim() || '';

  if (!/^rgba?\(.+?\)$/.test(cstr)) {
    // Convert both color names and hex colors to rgba
    const hexColor = convertColorNameToHex(color);
    return convertHexColorToRgba(hexColor);
  }

  // Convert rgb to rgba
  const channels = cstr.match(/([\-0-9.]+)/g) || [];

  switch (channels.length) {
    case 3:
      // Convert rgb to rgba
      return `rgba(${channels.join(', ')}, 1)`;

    case 4:
      // Format rgba
      return `rgba(${channels.join(', ')})`;

    default:
      // Unexpected color format. Leave it untouched (let the user handle it)
      return color;
  }
}
function convertColorToRGBA(color) {
  const cstr = `${color}`.toLowerCase().trim() || '';

  if (!/^rgba?\(.+?\)$/.test(cstr)) {
    // Convert both color names and hex colors to rgba
    const hexColor = convertColorNameToHex(color);
    return convertHexColorToRgba(hexColor);
  }

  // Convert rgb to rgba
  const channels = cstr.match(/([\-0-9.]+)/g) || [];

  switch (channels.length) {
    case 3:
      // Convert rgb to rgba
      return `rgba(${channels.join(', ')}, 1)`;

    case 4:
      // Format rgba
      return `rgba(${channels.join(', ')})`;

    default:
      // Unexpected color format. Leave it untouched (let the user handle it)
      return color;
  }
}
function convertColorToRGBA ( color ) { const cstr = ` ${ color } ` . toLowerCase ( ) . trim ( ) || '' ; if ( ! / ^rgba?\(.+?\)$ / . test ( cstr ) ) { // Convert both color names and hex colors to rgba const hexColor = convertColorNameToHex ( color ) ; return convertHexColorToRgba ( hexColor ) ; } // Convert rgb to rgba const channels = cstr . match ( / ([\-0-9.]+) / g ) || [ ] ; switch ( channels . length ) { case 3 : // Convert rgb to rgba return ` ${ channels . join ( ', ' ) } ` ; case 4 : // Format rgba return ` ${ channels . join ( ', ' ) } ` ; default : // Unexpected color format. Leave it untouched (let the user handle it) return color ; } }
Convert a colour to a normalised RGBA format
Required due to the different color formats
returned by different web drivers.

Examples:
rgb(85,0,0) => rgba(85, 0, 0, 1)

@param {string} color Color as a string, i.e. rgb(85,0,0)
Convert a colour to a normalised RGBA format Required due to the different color formats returned by different web drivers .