This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hexToRgba(st) { | |
if(st.startsWith("#")) | |
st = st.slice(1); | |
const len = st.length; // I don't know how JS works, I suspect this is recalculated | |
const has_alpha = !(len % 4); | |
if(len % 3 && !has_alpha) | |
throw new Error("invalid hex code"); | |
var val = Number.parseInt(st, 16); // Only parsing the string once is faster than slicing constantly |