You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[options.order]| <code>Array.<string></code> | One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object. |
158
158
|[options.customOrders]| <code>object</code> | A dictionary object containing one or more custom orders. Each custom order value must be an array defining the order expected values must be sorted in. |
159
159
|[options.computed]| <code>object</code> | A dictionary object containing one or more computed field functions. The function will be invoked once per item in the array. Each invocation will receive the array item as input and must return a primitive value by which the array can be sorted. |
160
+
|[options.nullRank]| <code>number</code> | Configures whether `null` values will be sorted before or after defined values. Set to `-1` for before, `1` for after. Defaults to `1`. |
161
+
|[options.undefinedRank]| <code>number</code> | Configures whether `undefined` values will be sorted before or after defined values. Set to `-1` for before, `1` for after. Defaults to `1`. |
Copy file name to clipboardExpand all lines: index.mjs
+12-5Lines changed: 12 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -17,12 +17,19 @@ import t from 'typical/index.mjs'
17
17
* @param {string[]} [options.order] - One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object.
18
18
* @param {object} [options.customOrders] - A dictionary object containing one or more custom orders. Each custom order value must be an array defining the order expected values must be sorted in.
19
19
* @param {object} [options.computed] - A dictionary object containing one or more computed field functions. The function will be invoked once per item in the array. Each invocation will receive the array item as input and must return a primitive value by which the array can be sorted.
20
+
* @param {number} [options.nullRank] - Configures whether `null` values will be sorted before or after defined values. Set to `-1` for before, `1` for after. Defaults to `1`.
21
+
* @param {number} [options.undefinedRank] - Configures whether `undefined` values will be sorted before or after defined values. Set to `-1` for before, `1` for after. Defaults to `1`.
20
22
* @returns {Array} Returns the array that was passed in.
21
23
* @alias module:sort-array
22
24
*/
23
25
functionsortArray(arr,options={}){
24
26
options=Object.assign(
25
-
{computed: {},customOrders: {}},
27
+
{
28
+
computed: {},
29
+
customOrders: {},
30
+
nullRank: 1,
31
+
undefinedRank: 1
32
+
},
26
33
options
27
34
)
28
35
arr.sort(getCompareFunc(options))
@@ -69,13 +76,13 @@ function getCompareFunc (options = {}) {
0 commit comments