Gathering detailed insights and metrics for array-sort
Gathering detailed insights and metrics for array-sort
Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.
npm install array-sort
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.3
Supply Chain
99.2
Quality
77.4
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
381,119,202
Last Day
200,550
Last Week
916,376
Last Month
4,201,089
Last Year
62,248,286
74 Stars
28 Commits
24 Forks
4 Watching
2 Branches
5 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
array-sort@1.0.0
Size
4.23 kB
NPM Version
5.3.0
Node Version
8.4.0
Publised On
06 Dec 2017
Cumulative downloads
Total Downloads
Last day
-5.6%
200,550
Compared to previous day
Last week
-14.6%
916,376
Compared to previous week
Last month
3.4%
4,201,089
Compared to previous month
Last year
-16.6%
62,248,286
Compared to previous year
3
7
Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.
Install with npm:
1$ npm install --save array-sort
Install with yarn:
1$ yarn add array-sort
Sort an array by the given object property:
1var arraySort = require('array-sort'); 2 3arraySort([{foo: 'y'}, {foo: 'z'}, {foo: 'x'}], 'foo'); 4//=> [{foo: 'x'}, {foo: 'y'}, {foo: 'z'}]
Reverse order
1arraySort([{foo: 'y'}, {foo: 'z'}, {foo: 'x'}], 'foo', {reverse: true}); 2//=> [{foo: 'z'}, {foo: 'y'}, {foo: 'x'}]
1arraySort(array, comparisonArgs);
array
: {Array} The array to sortcomparisonArgs
: {Function|String|Array}: One or more functions or object paths to use for sorting.1var arraySort = require('array-sort'); 2 3var posts = [ 4 { path: 'c.md', locals: { date: '2014-01-09' } }, 5 { path: 'a.md', locals: { date: '2014-01-02' } }, 6 { path: 'b.md', locals: { date: '2013-05-06' } }, 7]; 8 9// sort by `locals.date` 10console.log(arraySort(posts, 'locals.date')); 11 12// sort by `path` 13console.log(arraySort(posts, 'path'));
1var arraySort = require('array-sort'); 2 3var posts = [ 4 { locals: { foo: 'bbb', date: '2013-05-06' }}, 5 { locals: { foo: 'aaa', date: '2012-01-02' }}, 6 { locals: { foo: 'ccc', date: '2014-01-02' }}, 7 { locals: { foo: 'ccc', date: '2015-01-02' }}, 8 { locals: { foo: 'bbb', date: '2014-06-01' }}, 9 { locals: { foo: 'aaa', date: '2014-02-02' }}, 10]; 11 12// sort by `locals.foo`, then `locals.date` 13var result = arraySort(posts, ['locals.foo', 'locals.date']); 14 15console.log(result); 16// [ { locals: { foo: 'aaa', date: '2012-01-02' } }, 17// { locals: { foo: 'aaa', date: '2014-02-02' } }, 18// { locals: { foo: 'bbb', date: '2013-05-06' } }, 19// { locals: { foo: 'bbb', date: '2014-06-01' } }, 20// { locals: { foo: 'ccc', date: '2014-01-02' } }, 21// { locals: { foo: 'ccc', date: '2015-01-02' } } ]
If custom functions are supplied, array elements are sorted according to the return value of the compare function. See the docs for Array.sort()
for more details.
1var arr = [ 2 {one: 'w', two: 'b'}, 3 {one: 'z', two: 'a'}, 4 {one: 'x', two: 'c'}, 5 {one: 'y', two: 'd'}, 6]; 7 8function compare(prop) { 9 return function (a, b) { 10 return a[prop].localeCompare(b[prop]); 11 }; 12} 13 14var result = arraySort(arr, function (a, b) { 15 return a.two.localeCompare(b.two); 16}); 17 18console.log(result); 19// [ { one: 'z', two: 'a' }, 20// { one: 'w', two: 'b' }, 21// { one: 'x', two: 'c' }, 22// { one: 'y', two: 'd' } ]
1var arr = [ 2 {foo: 'w', bar: 'y', baz: 'w'}, 3 {foo: 'x', bar: 'y', baz: 'w'}, 4 {foo: 'x', bar: 'y', baz: 'z'}, 5 {foo: 'x', bar: 'x', baz: 'w'}, 6]; 7 8// reusable compare function 9function compare(prop) { 10 return function (a, b) { 11 return a[prop].localeCompare(b[prop]); 12 }; 13} 14 15// the `compare` functions can be a list or array 16var result = arraySort(arr, compare('foo'), compare('bar'), compare('baz')); 17 18console.log(result); 19// [ { foo: 'w', bar: 'y', baz: 'w' }, 20// { foo: 'x', bar: 'x', baz: 'w' }, 21// { foo: 'x', bar: 'y', baz: 'w' }, 22// { foo: 'x', bar: 'y', baz: 'z' } ]
a.b.c
) to get a nested value from an object. | homepage'a.b.c'
) paths. | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
10 | jonschlinkert |
4 | doowb |
1 | iamstolis |
1 | wkevina |
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
1$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on September 11, 2017.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 3/20 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More