@color-delta-e/utils
Version:
Utils package for color-delta-e
37 lines (30 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
const colorDeltaE = require('color-delta-e');
function filter(comparitor, filterList, options) {
options = { threshold: 5, type: "rgb", ...options };
return filterList.filter((color) => colorDeltaE.isPerceivable(comparitor, color, options));
}
function pipe(...funcs) {
return (base, startingList, options) => {
return funcs.reduce((acc, cur) => {
return cur(base, acc, options);
}, startingList);
};
}
const sortMap = {
asc: (type) => (comparitor) => (a, b) => {
return colorDeltaE.deltaE(comparitor, a, type) - colorDeltaE.deltaE(comparitor, b, type);
},
dec: (type) => (comparitor) => (a, b) => {
return colorDeltaE.deltaE(comparitor, b, type) - colorDeltaE.deltaE(comparitor, a, type);
}
};
function sort(comparitor, toSort, options) {
const direction = options?.direction || "asc";
const type = options?.type || "rgb";
return Array.from(toSort).sort(sortMap[direction](type)(comparitor));
}
exports.filter = filter;
exports.pipe = pipe;
exports.sort = sort;