typedash
Version:
modern, type-safe collection of utility functions
28 lines (26 loc) • 888 B
JavaScript
import { castArray } from './chunk-ETIDRXKH.js';
// src/functions/orderBy/orderBy.ts
function orderBy(array, iterators, orders) {
if (array == null)
return [];
const normalizedIteratees = castArray(iterators).map(
(iteratee) => typeof iteratee === "function" ? iteratee : (value) => value[iteratee]
);
const normalizedOrders = castArray(orders);
return [...array].sort((a, b) => {
for (const [index, iteratee] of normalizedIteratees.entries()) {
const normalizedOrder = normalizedOrders[index] ?? "asc";
const order = normalizedOrder === "desc" ? -1 : 1;
const aValue = iteratee(a);
const bValue = iteratee(b);
if (aValue < bValue)
return -1 * order;
if (aValue > bValue)
return 1 * order;
}
return 0;
});
}
export { orderBy };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=chunk-LOJMJYEC.js.map