That’s it Call function HspValue() and pass one parameter(hex value as string). — export const HspValue= (color: string): number => { const x = color.replace('#', ''); const r = parseInt(x.substring(0, 2), 16); const g = parseInt(x.substring(2, 4), 16); const b = parseInt(x.substring(4, 6), 16); const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b)); return hsp;