Skip to content

Commit

Permalink
refactor: trying to debug collection functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlwizard committed Nov 27, 2024
1 parent 660f787 commit f94e668
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
16 changes: 11 additions & 5 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function token(
srcChannelValues = (color as ColorTuple)
.filter((a) => eq(typeof a, "number"));

// @ts-ignore:
// @ts-ignore: check if it does not have a length as well
if (eq(typeof color, "object") && !color?.length)
// @ts-ignore:
srcChannelValues = srcChannels.map((a) => color[a]);
Expand Down Expand Up @@ -453,12 +453,18 @@ function token(
* converts any color token to an array or object equivalent
*/
function c2col(col: unknown) {
const res = targetMode ? parseToken(result, targetMode) : result;
srcChannels = targetMode ? gmchn(targetMode) : srcChannels;

if (and(and(eq(srcMode, "rgb"), normalizeRgb), not(targetMode)))

const res = targetMode
? parseToken(result, targetMode)
: result;
srcChannels = targetMode
? gmchn(targetMode)
: srcChannels;

if (((srcMode === "rgb" && normalizeRgb) && !targetMode))
// @ts-ignore:
if (srcChannels.some((c) => gt(Math.abs(result[c]), 1)))
if (srcChannels.some((c) => Math.abs(result[c]) > 1))
// @ts-ignore:
for (const k of srcChannels) result[k] /= 255;

Expand Down
12 changes: 6 additions & 6 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import { diverging, sortBy, filterBy, stats, colors } from "./lib/index.ts";

console.log(stats(colors('all', '600'), {
factor: ['chroma', 'hue']
factor: ['chroma', 'hue'], colorspace: 'lch'
}))


console.log(filterBy(colors('all', '500'), {
factor: ['chroma', 'hue'], ranges: {
hue: ['<100'], chroma: [20]
}, colorspace: 'lch'
}))
// console.log(filterBy(colors('all', '500'), {
// factor: ['chroma', 'hue'], ranges: {
// hue: ['<100'], chroma: [20]
// }, colorspace: 'lch'
// }))
12 changes: 6 additions & 6 deletions tests/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ const tests: Spec[] = [
{
description: "Filters collections of color.",
callback: filterBy,
matcher: "toEqual",

params: [samples, { ranges: { hue: ['>=190'], factor: ['hue'] } }],
result: "",

},
{
description: "Sorts collections of color.",
callback: sortBy,
matcher: "toEqual",

params: [samples, { factor: ['hue'], order: 'asc' }],
result: "",

},
{
description: "Gets the stats for a collection of color.",
callback: stats,
matcher: "toEqual",

params: [samples],
result: "",

},
// {
// description: "Distributes factors of a collection of color.",
Expand Down
2 changes: 1 addition & 1 deletion tests/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Spec = {
};
export default function (specs: Spec[]) {
for (const spec of specs) {
console.log(`${spec?.description} \n`, spec?.callback(...spec?.params), `\n`)
console.info(`${spec?.description} \n`, spec?.callback(...spec?.params), `\n`)
Deno.test(spec?.description || "Running test...", () => {
expect(spec?.callback(...spec?.params)).toBeTruthy()
});
Expand Down

0 comments on commit f94e668

Please sign in to comment.