typedash
Version:
modern, type-safe collection of utility functions
27 lines (24 loc) • 1.13 kB
TypeScript
import { Primitive } from 'type-fest';
import { K as KeysOfUnion } from '../KeysOfUnion-BrkZWXzm.js';
import { M as Many } from '../Many-Dnn8Ysh_.js';
import { M as Maybe } from '../Maybe-D6dwMjD9.js';
/**
* Sorts an array of objects by one or more properties, in ascending or descending order.
* @param array The array of objects to sort.
* @param iterators The property or properties to sort by. Can be a key of `TValue` or a function that returns a comparable value.
* @param orders The order or orders to sort by. Can be "asc" or "desc". Defaults to "asc".
* @returns A new array of objects sorted by the specified properties and orders.
*/
declare function orderBy<TValue>(array: Maybe<readonly TValue[]>, iterators: Many<OrderByIterator<TValue>>, orders?: Many<Order>): TValue[];
type Order = 'asc' | 'desc';
type OrderByIterator<TValue> = ((value: TValue) => ComparableValue) | KeysOfUnion<TValue>;
type ComparableValue = Exclude<Primitive, symbol> | {
[Symbol.toPrimitive](): Primitive;
} | {
valueOf(): Primitive;
} | {
toString(): string;
} | {
[Symbol.toStringTag]: string;
};
export { orderBy };