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]);
    }
  }
}
/**
 * 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!
 */
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!
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!
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]);
    }
  }
}
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 ] ) ; } } }
Parse a colour CSS colour string and return a RGBA object.
Parse a colour CSS colour string and return a RGBA object .