UNPKG

@signaldb/core

Version:

SignalDB is a client-side database that provides a simple MongoDB-like interface to the data with first-class typescript support to achieve an optimistic UI. Data persistence can be achieved by using storage providers that store the data through a JSON in

20 lines (19 loc) 828 B
import get from "./index2.mjs"; import { sort } from "fast-sort"; //#region src/utils/sortItems.ts /** * Sorts an array of items based on multiple fields and their specified sort order. * Uses the `fast-sort` library for efficient sorting. * @template T - The type of the items in the array. * @param items - The array of items to be sorted. * @param sortFields - An object defining the sort order for each field. * - Keys are the field names, and values are either `1` (ascending) or `-1` (descending). * @returns A new array of items sorted based on the specified fields and their order. */ function sortItems(items, sortFields) { return sort(items).by(Object.entries(sortFields).map(([key, value]) => { return { [value === 1 ? "asc" : "desc"]: (i) => get(i, key) }; })); } //#endregion export { sortItems as default };