Installations
npm install sort-es
Developer Guide
Typescript
Yes
Module System
CommonJS
Score
77.5
Supply Chain
100
Quality
83.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Languages
TypeScript (96.66%)
JavaScript (3.21%)
Shell (0.13%)
Developer
Download Statistics
Total Downloads
239,958
Last Day
421
Last Week
2,360
Last Month
11,232
Last Year
144,484
GitHub Statistics
46 Stars
283 Commits
5 Forks
5 Watching
4 Branches
1 Contributors
Bundle Size
2.01 kB
Minified
903.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.7.14
Package Id
sort-es@1.7.14
Unpacked Size
60.00 kB
Size
14.10 kB
File Count
42
Publised On
02 Jan 2025
Total Downloads
Cumulative downloads
Total Downloads
239,958
Last day
-5.4%
421
Compared to previous day
Last week
-13.6%
2,360
Compared to previous week
Last month
0.1%
11,232
Compared to previous month
Last year
107.7%
144,484
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
34
sort-es
Blazing fast, tree-shakeable, type-safe, modern utility library to sort any type of array
Docs : https://sort-es.netlify.app/
Getting started
installation
The library is available as a npm package. To install the package, run:
npm install sort-es
# or
yarn add sort-es
Start using:
1import {byString} from 'sort-es' 2 3const unsorted = ["xxx", "bbbb", "zzz", "cccc", "aaa"]; 4const sorted = unsorted.sort(byString()); 5 6console.log(sorted); //(5)Â ["aaa", "bbbb", "cccc", "xxx", "zzz"]
Use directly in the browser
1 2<script src='https://cdn.jsdelivr.net/npm/sort-es/dist/index.umd.js'></script> 3<script> 4 const unsorted = ["xxx", "bbbb", "zzz", "cccc", "aaa"]; 5 const sorted = unsorted.sort(sort.byString()); 6 7 console.log(sorted); //(5)Â ["aaa", "bbbb", "cccc", "xxx", "zzz"] 8</script> 9 10//or via browser modules 11 12<script type='module'> 13 import {byString} from 'https://cdn.jsdelivr.net/npm/sort-es/dist/index.mjs' 14 15 const unsorted = ["xxx", "bbbb", "zzz", "cccc", "aaa"]; 16 const sorted = unsorted.sort(byString()); 17 18 console.log(sorted); //(5)Â ["aaa", "bbbb", "cccc", "xxx", "zzz"] 19</script>
Some mind-blowing example
sort by a single property
1//js or ts file 2import {byValue, byNumber, byString} from 'sort-es' 3 4const arrayUnsorted = [ 5 {prop: "xxx", foo: 34}, 6 {prop: "aaa", foo: 325}, 7 {prop: "zzz", foo: 15}, 8 {prop: "ccc", foo: 340}, 9 {prop: "bbb", foo: 0} 10]; 11 12//this sort by the foo property ascending 13const sortedByFoo = arrayUnsorted.sort(byValue((i) => i.foo, byNumber())); 14console.log(sortedByFoo); //(5)Â [{prop: "bbb", foo : 0}, {prop: "zzz", foo: 15}, .....]; 15 16//this sort by the prop property descending 17const sortedByProp = arrayUnsorted.sort(byValue((i) => i.prop, byString({desc: true}))); 18console.log(sortedByProp); //(5)Â [{prop: "zzz", foo : 15}, {prop: "xxx", foo: 34}, .....];
sort by a multiple property
1//js or ts file 2import {byNumber, byString, byValues} from "sort-es"; 3 4const objsToSort = [ 5 {id: 2, name: 'teresa'}, 6 {id: 3, name: 'roberto'}, 7 {id: 2, name: 'roberto'} 8]; 9 10//i sort by THEIR NAMES and THEN by their ids 11const sortedObject = objsToSort.sort(byValues([ 12 [(x) => x.name, byString()], 13 [(x) => x.id, byNumber()] 14])); 15 16console.log(sortedObject); //[{roberto, 2}, {roberto, 3}, {teresa, 2}]; 17 18//i sort by THEIR IDS and THEN by their names 19const sortedObject2 = objsToSort.sort(byValues([ 20 [(x) => x.id, byNumber()], 21 [(x) => x.name, byString()] 22])); 23console.log(sortedObject2); //[{roberto, 2}, {teresa, 2}, {roberto, 3}]; 24 25//i sort by THEIR IDS and THEN by their names DESCENDING 26const sortedObject3 = objsToSort.sort(byValues([ 27 [(x) => x.id, byNumber()], 28 [(x) => x.name, byString({desc: true})], 29])); 30console.log(sortedObject3); //[{teresa, 2}, {roberto, 2}, {roberto, 3}]; 31
typescript types check
1//ts file 2import {byValue, byNumber, byString} from 'sort-es' 3 4const objsArray = [{numbProp: 2, stringProp: 'a'}, {numbProp: 3, stringProp: 'f'}]; 5 6//Incorrect sort property 7const incorrectSortedArray = objsArray.sort(byValue(i => i.numbProp, byString())); 8//ts check error : Type 'number' is not assignable to type 'string'. 9 10//Correct sort type 11const sortedArray = objsArray.sort(byValue(i => i.numbProp, byNumber())) 12//ts check ok 13
See full Docs
sort-es.netlify.app
License
MIT © Cosimo chellini
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
5 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 4
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/cosimochellini/sort-es/nodejs.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/nodejs.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/cosimochellini/sort-es/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/cosimochellini/sort-es/nodejs.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3.8
/10
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 MoreOther packages similar to sort-es
array.prototype.tosorted
An ESnext spec-compliant `Array.prototype.toSorted` shim/polyfill/replacement that works as far down as ES3.
@jay-es/eslint-plugin-vue-sort-components
A plugin for ESLint to keep order of component names
array.prototype.tospliced
An ESnext spec-compliant `Array.prototype.toSpliced` shim/polyfill/replacement that works as far down as ES3.
eslint-plugin-pinia-getters-no-array-mutations
eslint rule to disallow array methods that modify an array in-place in pinia getters because it can trigger endless recursions.