Skip to content

Commit 6989de4

Browse files
committed
update deps and readme
1 parent c237864 commit 6989de4

7 files changed

Lines changed: 207 additions & 44 deletions

File tree

README.hbs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Some trivial examples to demonstrate typical usage.
1818

1919
### Sorting an array of primitives
2020

21-
Sort an array of strings.
21+
#### Ascending order
22+
23+
Sort an array of strings in ascending order (the default).
2224

2325
```js
2426
> const partsOfTheDay = ['twilight', 'afternoon', 'morning', 'evening']
@@ -27,9 +29,18 @@ Sort an array of strings.
2729
[ 'afternoon', 'evening', 'morning', 'twilight' ]
2830
```
2931

32+
#### Descending order
33+
34+
Sort an array of strings in descending order.
35+
36+
```js
37+
> sortArray(partsOfTheDay, { order: 'desc' })
38+
[ 'twilight', 'morning', 'evening', 'afternoon' ]
39+
```
40+
3041
#### Custom sort order
3142

32-
The default sort order is `asc`. You can also specify `desc` or the name of a property from the `customOrders` object. For example, sort parts of the day by the order in which they occur.
43+
The default value for `options.order` is `'asc'`. You can also specify `'desc'` or the name of a property from the `customOrders` object. For example, sort parts of the day by the order in which they occur.
3344

3445
```js
3546
> sortArray(partsOfTheDay, {
@@ -43,6 +54,28 @@ The default sort order is `asc`. You can also specify `desc` or the name of a pr
4354

4455
### Sorting an array of objects
4556

57+
#### Sort by object property
58+
59+
Pass one or more property names to `options.by` to sort an array of objects by those properties.
60+
61+
```js
62+
> const repositories = [
63+
{ name: '75lb/sort-array', openIssues: 0, closedIssues: 4 },
64+
{ name: 'lwsjs/local-web-server', openIssues: 4, closedIssues: 80 },
65+
{ name: 'jsdoc2md/jsdoc-api', openIssues: 3, closedIssues: 47 }
66+
]
67+
68+
> sortArray(repositories, {
69+
by: 'openIssues',
70+
order: 'desc'
71+
})
72+
[
73+
{ name: 'lwsjs/local-web-server', openIssues: 4, closedIssues: 80 },
74+
{ name: 'jsdoc2md/jsdoc-api', openIssues: 3, closedIssues: 47 },
75+
{ name: '75lb/sort-array', openIssues: 0, closedIssues: 4 }
76+
]
77+
```
78+
4679
#### Sort by computed field
4780

4881
Sort by a computed field, i.e. a computed value that doesn't exist in the input dataset. Define your computed fields in the `options.computed` object, each value being a function which takes an array member as input and returns the primitive value to be sorted by. In this example we sort by `total` (the name of the computed field supplied in `options.computed`).

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Some trivial examples to demonstrate typical usage.
1818

1919
### Sorting an array of primitives
2020

21-
Sort an array of strings.
21+
#### Ascending order
22+
23+
Sort an array of strings in ascending order (the default).
2224

2325
```js
2426
> const partsOfTheDay = ['twilight', 'afternoon', 'morning', 'evening']
@@ -27,9 +29,18 @@ Sort an array of strings.
2729
[ 'afternoon', 'evening', 'morning', 'twilight' ]
2830
```
2931

32+
#### Descending order
33+
34+
Sort an array of strings in descending order.
35+
36+
```js
37+
> sortArray(partsOfTheDay, { order: 'desc' })
38+
[ 'twilight', 'morning', 'evening', 'afternoon' ]
39+
```
40+
3041
#### Custom sort order
3142

32-
The default sort order is `asc`. You can also specify `desc` or the name of a property from the `customOrders` object. For example, sort parts of the day by the order in which they occur.
43+
The default value for `options.order` is `'asc'`. You can also specify `'desc'` or the name of a property from the `customOrders` object. For example, sort parts of the day by the order in which they occur.
3344

3445
```js
3546
> sortArray(partsOfTheDay, {
@@ -43,6 +54,28 @@ The default sort order is `asc`. You can also specify `desc` or the name of a pr
4354

4455
### Sorting an array of objects
4556

57+
#### Sort by object property
58+
59+
Pass one or more property names to `options.by` to sort an array of objects by those properties.
60+
61+
```js
62+
> const repositories = [
63+
{ name: '75lb/sort-array', openIssues: 0, closedIssues: 4 },
64+
{ name: 'lwsjs/local-web-server', openIssues: 4, closedIssues: 80 },
65+
{ name: 'jsdoc2md/jsdoc-api', openIssues: 3, closedIssues: 47 }
66+
]
67+
68+
> sortArray(repositories, {
69+
by: 'openIssues',
70+
order: 'desc'
71+
})
72+
[
73+
{ name: 'lwsjs/local-web-server', openIssues: 4, closedIssues: 80 },
74+
{ name: 'jsdoc2md/jsdoc-api', openIssues: 3, closedIssues: 47 },
75+
{ name: '75lb/sort-array', openIssues: 0, closedIssues: 4 }
76+
]
77+
```
78+
4679
#### Sort by computed field
4780

4881
Sort by a computed field, i.e. a computed value that doesn't exist in the input dataset. Define your computed fields in the `options.computed` object, each value being a function which takes an array member as input and returns the primitive value to be sorted by. In this example we sort by `total` (the name of the computed field supplied in `options.computed`).
@@ -154,7 +187,7 @@ const sortArray = require('sort-array')
154187
| array | <code>Array</code> | The input array to sort. It is sorted in place. |
155188
| [options] | <code>object</code> | Sort options. |
156189
| [options.by] | <code>Array.&lt;string&gt;</code> | One or more property names or computed fields to sort by. Specifying property names is only relevant when sorting an array of objects. |
157-
| [options.order] | <code>Array.&lt;string&gt;</code> | One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object. |
190+
| [options.order] | <code>Array.&lt;string&gt;</code> | One or more sort orders. Specify `'asc'`, `'desc'` or a property name from the `options.customOrders` object. |
158191
| [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. |
159192
| [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. |
160193
| [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`. |

dist/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,11 @@
348348
* @param {Array} array - The input array to sort. It is sorted in place.
349349
* @param {object} [options] - Sort options.
350350
* @param {string[]} [options.by] - One or more property names or computed fields to sort by. Specifying property names is only relevant when sorting an array of objects.
351-
* @param {string[]} [options.order] - One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object.
351+
* @param {string[]} [options.order] - One or more sort orders. Specify `'asc'`, `'desc'` or a property name from the `options.customOrders` object.
352352
* @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.
353353
* @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.
354+
* @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`.
355+
* @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`.
354356
* @returns {Array} Returns the array that was passed in.
355357
* @alias module:sort-array
356358
*/

dist/index.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,11 @@ var t = {
342342
* @param {Array} array - The input array to sort. It is sorted in place.
343343
* @param {object} [options] - Sort options.
344344
* @param {string[]} [options.by] - One or more property names or computed fields to sort by. Specifying property names is only relevant when sorting an array of objects.
345-
* @param {string[]} [options.order] - One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object.
345+
* @param {string[]} [options.order] - One or more sort orders. Specify `'asc'`, `'desc'` or a property name from the `options.customOrders` object.
346346
* @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.
347347
* @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.
348+
* @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`.
349+
* @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`.
348350
* @returns {Array} Returns the array that was passed in.
349351
* @alias module:sort-array
350352
*/

index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import t from 'typical/index.mjs'
1414
* @param {Array} array - The input array to sort. It is sorted in place.
1515
* @param {object} [options] - Sort options.
1616
* @param {string[]} [options.by] - One or more property names or computed fields to sort by. Specifying property names is only relevant when sorting an array of objects.
17-
* @param {string[]} [options.order] - One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object.
17+
* @param {string[]} [options.order] - One or more sort orders. Specify `'asc'`, `'desc'` or a property name from the `options.customOrders` object.
1818
* @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.
1919
* @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.
2020
* @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`.

package-lock.json

Lines changed: 127 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
"typical": "^6.0.0"
3535
},
3636
"devDependencies": {
37-
"@test-runner/web": "^0.3.3",
37+
"@test-runner/web": "^0.3.4",
3838
"esm-runner": "^0.3.4",
3939
"isomorphic-assert": "^0.1.1",
4040
"jsdoc-to-markdown": "^5.0.3",
41-
"rollup": "^1.27.10",
41+
"rollup": "^1.31.0",
4242
"rollup-plugin-node-resolve": "^5.2.0",
4343
"test-object-model": "^0.6.1"
4444
},

0 commit comments

Comments
 (0)