JSFiddle - React, Tailwind, and code Playground
by Raul Bojalil
TypeScript
const invertColor = (color: string) => {
const padZero = (str: string) => {
var zeros = new Array(2).join('0');
return (zeros + str).slice(-2);
}
if (color.indexOf('#') === 0) {
color = color.slice(1);
}
const r = (255 - parseInt(color.slice(0, 2), 16)).toString(16);
const g = (255 - parseInt(color.slice(2, 4), 16)).toString(16);
const b = (255 - parseInt(color.slice(4, 6), 16)).toString(16);
return '#' + padZero(r) + padZero(g) + padZero(b);
}
alert(invertColor("#EDF354"));