Skip to content

Commit

Permalink
uppercase (#4852)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpkane authored Sep 26, 2024
1 parent 0b928cf commit e152852
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions app/packages/state/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -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 } });
});
});
8 changes: 4 additions & 4 deletions app/packages/state/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }];
})
);
};
Expand Down

0 comments on commit e152852

Please sign in to comment.