export { hexToRgba, hexToRgbaNormal };

/* Converts a string of the form "#XXXXXX"
 * 
*/
function hexToRgba(hex) {
  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex.toLowerCase());
  return result ? {
    r: parseInt(result[1], 16),
    g: parseInt(result[2], 16),
    b: parseInt(result[3], 16),
    a: result.length == 4 ? parseInt(result[4], 16) : 255.,
  } : null;
}

function hexToRgbaNormal(hex) {
  var result = hexToRgba(hex);
  return result ? {
    r: result.r / 255.,
    g: result.g / 255.,
    b: result.b / 255.,
    a: result.a / 255.,
  } : null;
}
