1

Hex To Rgb

Function JavaScript 1 revisions 89 6 months ago 6 months ago
function hexToRgb(hex) {
  hex = hex.padStart(8, 'ff');
  const rgb = {
    r: parseInt(hex.slice(2, 4), 16),
    g: parseInt(hex.slice(4, 6), 16),
    b: parseInt(hex.slice(6, 8), 16),
    a: parseInt(hex.slice(0, 2), 16)
  }
  return rgb;
}

Simple function to convert hex to rgb.