UNPKG

ts-prime

Version:

A utility library for JavaScript and Typescript.

32 lines 1.16 kB
export declare type SortValue = boolean | number | string; export declare type ComplexSort = { order?: 'asc' | 'desc'; value: SortValue; compare?: (a: SortValue, b: SortValue) => number; }; export declare type SortByProp = SortValue | ComplexSort | (SortValue | ComplexSort)[]; /** * Sorts the list according to the supplied function in ascending order. * Sorting is based on a native `sort` function. It's not guaranteed to be stable. * @param array - the array to sort * @param fn - the mapping function * @signature * P.sortBy(array, fn) * @signature * P.sortBy(fn)(array) * @example * P.sortBy( * [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }], * x => x.a * ) * // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] * * P.pipe( * [{ a: 1 }, { a: 3 }, { a: 7 }, { a: 2 }], * P.sortBy(x => x.a) * ) // => [{ a: 1 }, { a: 2 }, { a: 3 }, { a: 7 }] * @category Array, Pipe */ export declare function sortBy<T>(array: readonly T[], fn: (item: T) => SortByProp): T[]; export declare function sortBy<T>(fn: (item: T) => SortByProp): (array: readonly T[]) => T[]; //# sourceMappingURL=sortBy.d.ts.map