const hexToDecS = "0123456789ABCDEF"; const hexToDecI = (c: string): number => c .split("") .reverse() .reduce( (acc: number, c: string, i: number) => Math.pow(16, i) * hexToDecS.indexOf(c.toUpperCase()) + acc, 0 ); const isHex = new RegExp("^[0-9a-fA-F][0-9a-fA-F]?$"); export const hexToDec = (r: string, g: string, b: string) => { if (!(r.match(isHex) && g.match(isHex) && b.match(isHex))) { console.error("hexToDec passed an unrecognizable number."); return null; } return [hexToDecI(r), hexToDecI(g), hexToDecI(b)]; };