Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sort-array

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sort-array - npm Package Compare versions

Comparing version 4.1.0-0 to 4.1.0

4

dist/index.js

@@ -351,5 +351,7 @@ (function (global, factory) {

* @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.
* @param {string[]} [options.order] - One or more sort orders. Specify `asc`, `desc` or a property name from the `options.customOrders` object.
* @param {string[]} [options.order] - One or more sort orders. Specify `'asc'`, `'desc'` or a property name from the `options.customOrders` object.
* @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.
* @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.
* @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`.
* @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`.
* @returns {Array} Returns the array that was passed in.

@@ -356,0 +358,0 @@ * @alias module:sort-array

@@ -7,3 +7,3 @@ {

],
"version": "4.1.0-0",
"version": "4.1.0",
"description": "Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order",

@@ -38,7 +38,7 @@ "repository": "https://github.com/75lb/sort-array",

"devDependencies": {
"@test-runner/web": "^0.3.3",
"@test-runner/web": "^0.3.4",
"esm-runner": "^0.3.4",
"isomorphic-assert": "^0.1.1",
"jsdoc-to-markdown": "^5.0.3",
"rollup": "^1.27.10",
"rollup": "^1.31.0",
"rollup-plugin-node-resolve": "^5.2.0",

@@ -45,0 +45,0 @@ "test-object-model": "^0.6.1"

@@ -21,4 +21,6 @@ [![view on npm](http://img.shields.io/npm/v/sort-array.svg)](https://www.npmjs.org/package/sort-array)

Sort an array of strings.
#### Ascending order
Sort an array of strings in ascending order (the default).
```js

@@ -31,5 +33,14 @@ > const partsOfTheDay = ['twilight', 'afternoon', 'morning', 'evening']

#### Descending order
Sort an array of strings in descending order.
```js
> sortArray(partsOfTheDay, { order: 'desc' })
[ 'twilight', 'morning', 'evening', 'afternoon' ]
```
#### Custom sort order
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.
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.

@@ -48,2 +59,24 @@ ```js

#### Sort by object property
Pass one or more property names to `options.by` to sort an array of objects by those properties.
```js
> const repositories = [
{ name: '75lb/sort-array', openIssues: 0, closedIssues: 4 },
{ name: 'lwsjs/local-web-server', openIssues: 4, closedIssues: 80 },
{ name: 'jsdoc2md/jsdoc-api', openIssues: 3, closedIssues: 47 }
]
> sortArray(repositories, {
by: 'openIssues',
order: 'desc'
})
[
{ name: 'lwsjs/local-web-server', openIssues: 4, closedIssues: 80 },
{ name: 'jsdoc2md/jsdoc-api', openIssues: 3, closedIssues: 47 },
{ name: '75lb/sort-array', openIssues: 0, closedIssues: 4 }
]
```
#### Sort by computed field

@@ -160,3 +193,3 @@

| [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. |
| [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. |
| [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. |
| [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. |

@@ -163,0 +196,0 @@ | [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. |

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc