type sortOptions = { /** * Filter function to apply to the array before sorting * (default=isNotEmptyObject) */ filter_fn?: (el: T) => boolean; /** * Remove objects that don't have the key or where the key is falsy * (default=false) */ nokey_hide?: boolean; /** * Move invalid values (eg: non-objects or objects that don't match the key/function passed) to the end of the sorted array * (default=true) */ nokey_atend?: boolean; }; type sortByFunction = (el: Record) => string; /** * Sort an array of objects. * * The internals of this function swap between insertion and quicksort depending on the use-case. * Insertion sort is used for smaller arrays and quicksort is used for larger arrays. * * The threshold for insertion sort is 10 elements. * * The quicksort implementation is based on Tony Hoare's quicksort * (https://cs.stanford.edu/people/eroberts/courses/soco/projects/2008-09/tony-hoare/quicksort.html) * * Example: * sort([ * {test: 'Peter'}, * {test: 'Jack'}, * {test: 'Pony'}, * {test: 'John'}, * {test: 'Joe'}, * {test: 'Bob'}, * {test: 'Alice'}, * ], 'test', 'desc'); * Output: * [{test: 'Pony'}, {test: 'Peter'}, {test: 'John'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}] * * Example w/ Function: * sort([ * {test: 'Peter'}, * {test: 'Pony'}, * {test: 'JOHn'}, * {test: 'Joe'}, * ], el => el.test.toLowerCase(), 'desc'); * Output: * [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Joe'}] * * @param {Array} val - Array to sort * @param {string|sortByFunction} by - Either a string (key) or a function * @param {'desc'|'asc'} dir - (default='asc') Direction to sort in (asc or desc) * @param {sortOptions} opts - Sort options * @throws {Error} */ declare function sort(arr: T[], by: string | sortByFunction, dir?: 'asc' | 'desc', opts?: sortOptions): T[]; export { sort, sort as default };