diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 6bbe65b6..7b0f97ce 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,6 +6,7 @@ "yoavbls.pretty-ts-errors", "bradlc.vscode-tailwindcss", "unifiedjs.vscode-mdx", - "github.vscode-github-actions" + "github.vscode-github-actions", + "aaron-bond.better-comments" ] } diff --git a/lib/utils.ts b/lib/utils.ts index 80dacd8e..e2f1a6be 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -427,9 +427,9 @@ function token( if (eq(typeof color, "string")) // @ts-ignore: - result = eq(typeof color, "number") - ? num2c() - : parseToken(c2str(), "rgb"); + result = (typeof color === "number" + && num2c()) + || parseToken(c2str(), "rgb"); // @ts-ignore: diff --git a/test.ts b/test.ts index e9b62aeb..ab77bdd4 100644 --- a/test.ts +++ b/test.ts @@ -4,7 +4,7 @@ import { diverging, sortBy, filterBy, stats, colors } from "./lib/index.ts"; import { mc, token } from "./lib/utils.ts"; // console.log(stats(colors('all', '600'), { -// factor: ['chroma', 'hue'], colorspace: 'lch' +// factor: ['chroma', 'hue'], colorspace: 'lch'zzzzzzz // })) @@ -16,6 +16,10 @@ import { mc, token } from "./lib/utils.ts"; //console.info(sortBy(['purple', 'blue'], { relative: true, factor: ['chroma', 'hue'] })) +// * fix this +// ! fix this +// ? fix this +// todo //console.log(mc('rgb.b')(['rgb', 0.4, 0.3, 0.1])) console.log(mc('lch.h')({ r: 0.2, g: 0.4, b: 0.5, mode: 'rgb' })) diff --git a/tests/utils.test.ts b/tests/utils.test.ts index 1e4c6826..1a2dfc71 100644 --- a/tests/utils.test.ts +++ b/tests/utils.test.ts @@ -4,7 +4,7 @@ import runner, { type Spec } from "./runner.ts"; -const str = '#ffc300', arr = ['rgb', 0.4, 0.3, 0.1], obj = { r: 0.2, g: 0.4, b: 0.5, mode: 'rgb' }, fn_mc = (a: string, b: string) => mc(a)(b) +const str = '#ffc3003f', arr = ['rgb', 0.4, 0.3, 0.1, 0.7], obj = { r: 0.2, g: 0.4, b: 0.5, mode: 'rgb' }, fn_mc = (a: string, b: string) => mc(a)(b) const specs: Spec[] = [{ description: "converts an object to a number", callback: token, @@ -16,19 +16,19 @@ const specs: Spec[] = [{ params: [str, { kind: 'arr', targetMode: 'lab' }] }, { - description: "converts an array to a hex string", + description: "converts an array to a 6 character hex string (without the alpha channel). ", callback: token, - params: [arr, { kind: 'str' }] + params: [arr, { kind: 'str', omitAlpha: true }] }, { - description: "converts an array to an object", + description: "converts an array to an object without alpha and mode properties", callback: token, - params: [arr, { kind: 'obj' }] + params: [arr, { kind: 'obj', omitMode: true, omitAlpha: true }] }, { - description: "converts an object to an array", + description: "converts an object to an array of channel values with no mode string.", callback: token, - params: [obj, { kind: 'arr' }] + params: [obj, { kind: 'arr', omitMode: true }] }, { description: "converts an array to a number", @@ -42,6 +42,10 @@ const specs: Spec[] = [{ description: 'gets the channel value of a color object', callback: fn_mc, params: ['lch.l', obj] +}, { + description: 'sets the channel value of a color object', + callback: fn_mc, + params: ['lch.h', obj, '*0.2'] } ];