UNPKG

@color-delta-e/utils

Version:
31 lines (26 loc) 924 B
import { isPerceivable, deltaE } from 'color-delta-e'; function filter(comparitor, filterList, options) { options = { threshold: 5, type: "rgb", ...options }; return filterList.filter((color) => 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 deltaE(comparitor, a, type) - deltaE(comparitor, b, type); }, dec: (type) => (comparitor) => (a, b) => { return deltaE(comparitor, b, type) - 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)); } export { filter, pipe, sort };