source: node_modules/es-toolkit/dist/compat/array/orderBy.d.ts@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.7 KB
Line 
1import { ListIteratee } from '../_internal/ListIteratee.js';
2import { ListIterator } from '../_internal/ListIterator.js';
3import { Many } from '../_internal/Many.js';
4import { ObjectIteratee } from '../_internal/ObjectIteratee.js';
5import { ObjectIterator } from '../_internal/ObjectIterator.js';
6
7/**
8 * Sorts an array of elements based on multiple iteratee functions and their corresponding order directions.
9 *
10 * @template T The type of elements in the array
11 * @param {ArrayLike<T> | null | undefined} collection The array to sort
12 * @param {Many<ListIterator<T, unknown>>} iteratees The iteratee functions to sort by
13 * @param {Many<boolean | 'asc' | 'desc'>} orders The sort orders
14 * @returns {T[]} Returns the new sorted array
15 * @example
16 * const users = [
17 * { name: 'fred', age: 48 },
18 * { name: 'barney', age: 34 }
19 * ];
20 *
21 * // Sort by age in ascending order
22 * orderBy(users, [(user) => user.age], ['asc']);
23 * // => [{ name: 'barney', age: 34 }, { name: 'fred', age: 48 }]
24 */
25declare function orderBy<T>(collection: ArrayLike<T> | null | undefined, iteratees?: Many<ListIterator<T, unknown>>, orders?: Many<boolean | 'asc' | 'desc'>): T[];
26/**
27 * Sorts an array of elements based on multiple property names/paths and their corresponding order directions.
28 *
29 * @template T The type of elements in the array
30 * @param {ArrayLike<T> | null | undefined} collection The array to sort
31 * @param {Many<ListIteratee<T>>} iteratees The property names/paths to sort by
32 * @param {Many<boolean | 'asc' | 'desc'>} orders The sort orders
33 * @returns {T[]} Returns the new sorted array
34 * @example
35 * const users = [
36 * { name: 'fred', age: 48 },
37 * { name: 'barney', age: 34 }
38 * ];
39 *
40 * // Sort by name in ascending order
41 * orderBy(users, ['name'], ['asc']);
42 * // => [{ name: 'barney', age: 34 }, { name: 'fred', age: 48 }]
43 */
44declare function orderBy<T>(collection: ArrayLike<T> | null | undefined, iteratees?: Many<ListIteratee<T>>, orders?: Many<boolean | 'asc' | 'desc'>): T[];
45/**
46 * Sorts an object's values based on multiple iteratee functions and their corresponding order directions.
47 *
48 * @template T The object type
49 * @param {T | null | undefined} collection The object to sort values from
50 * @param {Many<ObjectIterator<T, unknown>>} iteratees The iteratee functions to sort by
51 * @param {Many<boolean | 'asc' | 'desc'>} orders The sort orders
52 * @returns {Array<T[keyof T]>} Returns the new sorted array
53 * @example
54 * const obj = {
55 * a: { name: 'fred', age: 48 },
56 * b: { name: 'barney', age: 34 }
57 * };
58 *
59 * // Sort by age in ascending order
60 * orderBy(obj, [(user) => user.age], ['asc']);
61 * // => [{ name: 'barney', age: 34 }, { name: 'fred', age: 48 }]
62 */
63declare function orderBy<T extends object>(collection: T | null | undefined, iteratees?: Many<ObjectIterator<T, unknown>>, orders?: Many<boolean | 'asc' | 'desc'>): Array<T[keyof T]>;
64/**
65 * Sorts an object's values based on multiple property names/paths and their corresponding order directions.
66 *
67 * @template T The object type
68 * @param {T | null | undefined} collection The object to sort values from
69 * @param {Many<ObjectIteratee<T>>} iteratees The property names/paths to sort by
70 * @param {Many<boolean | 'asc' | 'desc'>} orders The sort orders
71 * @returns {Array<T[keyof T]>} Returns the new sorted array
72 * @example
73 * const obj = {
74 * a: { name: 'fred', age: 48 },
75 * b: { name: 'barney', age: 34 }
76 * };
77 *
78 * // Sort by name in ascending order
79 * orderBy(obj, ['name'], ['asc']);
80 * // => [{ name: 'barney', age: 34 }, { name: 'fred', age: 48 }]
81 */
82declare function orderBy<T extends object>(collection: T | null | undefined, iteratees?: Many<ObjectIteratee<T>>, orders?: Many<boolean | 'asc' | 'desc'>): Array<T[keyof T]>;
83
84export { orderBy };
Note: See TracBrowser for help on using the repository browser.