Gathering detailed insights and metrics for sort-any
Gathering detailed insights and metrics for sort-any
Gathering detailed insights and metrics for sort-any
Gathering detailed insights and metrics for sort-any
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.
gulp-sort
Sort files in stream by path or any custom sort comparator
sort-array
Isomorphic, load-anywhere function to sort an array by scalar, deep or computed values in any standard or custom order
sort-es
Blazing fast, tree-shakeable, type-safe, modern utility library to sort any type of array in less than 1 KB!
Sorts any JavaScript array in a predictable way (deep equal arrays are always sorted in the same order)
npm install sort-any
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98.7
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
47,525,154
Last Day
30,830
Last Week
588,089
Last Month
2,510,594
Last Year
25,262,362
4 Stars
200 Commits
2 Watchers
6 Branches
4 Contributors
Updated on Mar 07, 2023
Minified
Minified + Gzipped
Latest Version
4.0.6
Package Id
sort-any@4.0.6
Unpacked Size
10.22 kB
Size
3.14 kB
File Count
3
NPM Version
7.7.6
Node Version
14.21.3
Published on
Apr 07, 2024
Cumulative downloads
Total Downloads
Last Day
2.3%
30,830
Compared to previous day
Last Week
-5.4%
588,089
Compared to previous week
Last Month
0.8%
2,510,594
Compared to previous month
Last Year
177.7%
25,262,362
Compared to previous year
1
22
JS library which always sorts arrays in a predictable way. Moreover in contrary to Array.prototype.sort
, it does not modify the argument.
Array.prototype.sort
:
1[[[11]],[[2]],2,{foo:{foo:2}},1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:1},{foo:0},{foo:{}}].sort() 2/* 3It gives: 4[ 1, 5 [ 1, 2 ], 6 [ [ 11 ] ], 7 2, 8 2, 9 [ [ 2 ] ], 10 [ 3, 4 ], 11 32, 12 4, 13 { foo: { foo: 2 } }, 14 { foo: {} }, 15 { foo: 1 }, 16 { foo: 0 }, 17 { foo: { foo: 1 } } ] 18*/
The same array in a different order:
1[[[11]],[[2]],2,1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:0},{foo:1},{foo:{}},{foo:{foo:2}}].sort() 2/* 3It gives: 4[ 1, 5 [ 1, 2 ], 6 [ [ 11 ] ], 7 2, 8 2, 9 [ [ 2 ] ], 10 [ 3, 4 ], 11 32, 12 4, 13 { foo: { foo: 1 } }, 14 { foo: 0 }, 15 { foo: 1 }, 16 { foo: {} }, 17 { foo: { foo: 2 } } ] 18*/
So the results of Array.prototype.sort
are strange (eg. numbers are sorted in the alphabetical order) and moreover if we change the array order (eg. for object items), the result has order changed as well.
So I have implemented this library to work like that:
1const sort = require('sort-any'); 2sort([[[11]],[[2]],2,{foo:{foo:2}},1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:1},{foo:0},{foo:{}}]) 3/* 4It returns: 5[ 1, 6 2, 7 2, 8 4, 9 32, 10 [ [ 2 ] ], 11 [ [ 11 ] ], 12 [ 1, 2 ], 13 [ 3, 4 ], 14 { foo: 0 }, 15 { foo: 1 }, 16 { foo: {} }, 17 { foo: { foo: 1 } }, 18 { foo: { foo: 2 } } ] 19*/
And when we change the order, the result remains the same.
1const sort = require('sort-any'); 2sort([[[11]],[[2]],2,1,4,2,{foo:{foo:1}},32,[3,4],[1,2],{foo:0},{foo:1},{foo:{}},{foo:{foo:2}}]) 3/* 4It returns: 5[ 1, 6 2, 7 2, 8 4, 9 32, 10 [ [ 2 ] ], 11 [ [ 11 ] ], 12 [ 1, 2 ], 13 [ 3, 4 ], 14 { foo: 0 }, 15 { foo: 1 }, 16 { foo: {} }, 17 { foo: { foo: 1 } }, 18 { foo: { foo: 2 } } ] 19*/
Rules for sorting:
false
is less than true
-Infinity
is less than any other numberInfinity
is more than any other numberObject.keys(object)[0]
)No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license 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
Reason
43 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
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