diff --git a/src/__tests__/helper.test.ts b/src/__tests__/helper.test.ts index cb76723..de78511 100644 --- a/src/__tests__/helper.test.ts +++ b/src/__tests__/helper.test.ts @@ -1,7 +1,17 @@ -import { removeRgbaBlank } from "../utils/helper"; +import { removeRgbaBlank, getColorType } from "../utils/helper"; describe("helper", () => { it("helper", () => { expect(removeRgbaBlank('rgba(0, 0, 0, 1)')).toBe('rgba(0,0,0,1)'); }); -}); + + it("getColorType", () => { + expect(getColorType("rgba(255,255,255,1)")).toBe('rgba'); + expect(getColorType("rgba(0,0,0,0)")).toBe('rgba'); + expect(getColorType("rgb(255,255,255)")).toBe('rgb'); + expect(getColorType("rgb(0,0,0)")).toBe('rgb'); + expect(getColorType('#ffffffff')).toBe('hex'); + expect(getColorType('#ffffff')).toBe('hex'); + expect(getColorType('#fff')).toBe('hex'); + }) +}); \ No newline at end of file diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 70f801b..1486df3 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -1,3 +1,13 @@ +import { isHex, isRgba, isRgb } from "./validator"; + export const removeRgbaBlank = (color: string) => { return color.replace(/\s+/g, ""); }; + +export const getColorType = (color: string) => { + if (isHex(color)) return "hex"; + if (isRgb(color)) return "rgb"; + if (isRgba(color)) return "rgba"; + + return ""; +};