diff --git a/src/utils/hexToRgb.ts b/src/utils/hexToRgb.ts new file mode 100644 index 0000000..bfb2c31 --- /dev/null +++ b/src/utils/hexToRgb.ts @@ -0,0 +1,21 @@ +const hexToRGB = (h: string) => { + let r: number | string = 0, + g: number | string = 0, + b: number | string = 0; + + // 3 digits + if (h.length == 4) { + r = "0x" + h[1] + h[1]; + g = "0x" + h[2] + h[2]; + b = "0x" + h[3] + h[3]; + + // 6 digits + } else if (h.length == 7) { + r = "0x" + h[1] + h[2]; + g = "0x" + h[3] + h[4]; + b = "0x" + h[5] + h[6]; + } + + return "rgb(" + +r + "," + +g + "," + +b + ")"; +}; +export default hexToRGB;