UNPKG

fast-sort-lens

Version:
33 lines (31 loc) 860 B
import { sort, sort as sort$1 } from "fast-sort"; //#region src/index.ts /** * just like _.orderBy API spec, (_: lodash / es-toolkit) */ function fastOrderBy(list, props, orders) { if (props.length !== orders.length) throw new Error("props & orders length not match"); const _by = props.map((prop, index) => { const order = orders[index]; if (order === "asc") return { asc: prop }; else if (order === "desc") return { desc: prop }; return { asc: prop, comparer: order }; }); return sort$1(list).by(_by); } function fastSortWithRules(list, rules) { const _by = rules.map(({ order, prop }) => { if (order === "asc") return { asc: prop }; else if (order === "desc") return { desc: prop }; return { asc: prop, comparer: order }; }); return sort$1(list).by(_by); } //#endregion export { fastOrderBy, fastSortWithRules, sort };