From 3084e9d7c13621154768b118ff737ebd9c690bbc Mon Sep 17 00:00:00 2001 From: Benjamin Kane Date: Thu, 26 Sep 2024 11:51:39 -0400 Subject: [PATCH] uppercase --- app/packages/state/src/utils.test.ts | 10 ++++++++++ app/packages/state/src/utils.ts | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 app/packages/state/src/utils.test.ts diff --git a/app/packages/state/src/utils.test.ts b/app/packages/state/src/utils.test.ts new file mode 100644 index 0000000000..94e7b0cd8c --- /dev/null +++ b/app/packages/state/src/utils.test.ts @@ -0,0 +1,10 @@ +import { describe, expect, it } from "vitest"; +import { convertTargets } from "./utils"; + +describe("convertTargets", () => { + it("upper cases rgb hex targets", () => { + expect( + convertTargets([{ target: "#ffffff", value: "white" }]) + ).toStrictEqual({ "#FFFFFF": { label: "white", intTarget: 1 } }); + }); +}); diff --git a/app/packages/state/src/utils.ts b/app/packages/state/src/utils.ts index f3c1c7d191..1bb9e0c99a 100644 --- a/app/packages/state/src/utils.ts +++ b/app/packages/state/src/utils.ts @@ -113,22 +113,22 @@ export const getStandardizedUrls = ( return Object.fromEntries(urls.map(({ field, url }) => [field, url])); }; -const convertTargets = ( +export const convertTargets = ( targets: { target: string; value: string; }[] -) => { +): { [key: string]: { label: string; intTarget: number } | string } => { return Object.fromEntries( (targets || []).map(({ target, value }, i) => { - if (!isNaN(Number(target))) { + if (!Number.isNaN(Number(target))) { // masks targets is for non-rgb masks return [target, value]; } // convert into RGB mask representation // offset of 1 in intTarget because 0 has a special significance - return [target, { label: value, intTarget: i + 1 }]; + return [target.toUpperCase(), { label: value, intTarget: i + 1 }]; }) ); };