Skip to content

Interface: SortArrayOptions<Computed> ​

How sortArray sorts: by which properties, in which order.

Type Parameters ​

Computed ​

Computed

Properties ​

by? ​

optional by?: string | string[]

The property to sort the items by, or several: the next one breaks the ties of the previous one. A name of computed sorts by that function's result. An item whose property is undefined (or missing) has the key undefined (see undefinedRank).

Default ​

ts
none (the items themselves are compared)

computed? ​

optional computed?: object

Computed sort keys: a name used in by mapped to a function of the item returning its key. Used for an item whose property of that name is undefined.

Index Signature ​

[key: string]: (item) => string | number | bigint | boolean | symbol | null | undefined


customOrders? ​

optional customOrders?: object

Named custom orders: a name, given in order, mapped to the list of the values in their order ({order: 'priority', customOrders: {priority: ['high', 'medium', 'low']}}). A value missing from the list goes before the values in it.

Index Signature ​

[key: string]: any


nullRank? ​

optional nullRank?: 1 | -1

Where the null keys go, in both orders: 1 after the other values, -1 before them.

Default ​

ts
1

order? ​

optional order?: string | string[]

The order: 'asc', 'desc' or the name of a custom order of customOrders, or one per property of by. Any other value leaves the items unsorted.

Default ​

ts
'asc'

undefinedRank? ​

optional undefinedRank?: 1 | -1

Where the undefined keys go, in both orders: 1 after the other values, -1 before them. An item which is itself undefined always goes last (Array.prototype.sort does not compare it).

Default ​

ts
1

Released under the MIT License.