New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fast-sort

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-sort - npm Package Compare versions

Comparing version 1.5.4 to 1.5.5

2

package.json

@@ -1,1 +0,1 @@

{"name":"fast-sort","version":"1.5.4","description":"Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.","main":"sort.js","author":"Stefan Novakovic <stefan.novakovich@gmail.com>","license":"MIT","homepage":"https://github.com/snovakovic/fast-sort#readme","scripts":{"test":"node integration_test/index.js","publish":"node publish"},"repository":{"type":"git","url":"git+https://github.com/snovakovic/js-flock.git"},"bugs":{"url":"https://github.com/snovakovic/js-flock/issues"},"keywords":["sort","sortBy","order","orderBy"]}
{"name":"fast-sort","version":"1.5.5","description":"Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.","main":"sort.js","author":"Stefan Novakovic <stefan.novakovich@gmail.com>","license":"MIT","homepage":"https://github.com/snovakovic/fast-sort#readme","scripts":{"test":"node integration_test/index.js","publish":"node publish"},"repository":{"type":"git","url":"git+https://github.com/snovakovic/js-flock.git"},"bugs":{"url":"https://github.com/snovakovic/js-flock/issues"},"keywords":["sort","sortBy","order","orderBy"]}

@@ -12,16 +12,32 @@ # fast-sort

Blazing fast array sorting that **outperforms lodash sorting by ~2x** (in some cases it's more then 5x).
Blazing fast array sorting that **outperforms lodash sorting by ~2x** (in some cases it's more than 5x).
Take a look at the benchmark section for more information about performance.
### Quick example
```javascript
// Sort flat array
sort([1,4,2]).asc(); // => [1, 2, 4]
// Sort array of objects
sort(users).desc(u => u.firstName);
// Sort in multiple directions
sort(users).by([
{ asc: 'name' }
{ desc: 'age' }
]);
```
### Fast sort highlights
* Sorting an array of objects by one or more properties
* Sorting flat arrays
* Sorting in multiple directions
* Easy to read syntax for asc and desc sorting
* Faster then other sort alternatives
* Undefined and null values are always sorted to bottom of list no matter if ordering is ascending or descending.
* Sort array of objects by one or more properties
* Sort flat arrays
* Sort in multiple directions
* Easy to read syntax
* Faster than other popular sort alternatives
* Undefined and null values are always sorted to bottom
Under the hood sort use a [native JavaScript sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).
Usage of native sort implies that sorting is not necessarily [stable](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability) and it also implies that input array is modified(sorted) same as it would be when applying native sort
Usage of native sort implies that sorting is not necessarily [stable](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability) and it also implies that input array is modified(sorted) same as it would be when applying native sort.

@@ -36,3 +52,3 @@ ### Example

// Sort users [Object] ascending by firstName
// Sort users Object[] ascending by firstName
sort(users).asc(u => u.firstName);

@@ -56,3 +72,3 @@

// NOTE: Available from version [1.5.0]
sort(persons).by([
sort(users).by([
{ asc: 'name' }

@@ -68,2 +84,13 @@ { desc: 'age' }

sort(33).desc(); // => 33
// By default sort is mutating input array,
const arr = [1, 4, 2];
const sortedArr = sort(arr).asc();
console.log(arr) // => [1, 2, 4]
// We can easily prevent mutating of input array by using ES6 spread operator
const arr = [1, 4, 2];
const sortedArr = sort([...arr]).asc();
console.log(arr) // => [1, 4, 2]
console.log(sortedArr) // => [1, 2, 4]
```

@@ -76,7 +103,7 @@

Benchmarking sort is not an easy task as there is so many different scenarios that can happen while sorting.
Because of that 5 different benchmarks have been created to test how fast-sort is behaving on different inputs and sort scenarios.
Each benchmark is run with different array sizes from small 100 items to large 100 000 items.
Five different benchmarks have been created to get better insight of how fast-sort perform under different scenarios.
Each benchmark is run with different array sizes raging from small 100 items to large 100 000 items.
Every run of benchmark outputs different results but the results are constantly better then lodash sort and in following benchmark score ranges from 1.37x to 13.51x faster then lodash sort. This will vary on each benchmark run but it should not vary too much.
Every run of benchmark outputs different results but the results are constantly showing better scores compared to
similar popular sorting libraries.

@@ -83,0 +110,0 @@

@@ -1,1 +0,1 @@

!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r.sort=r.sort||{},r.sort.js=n())}(this,function(){"use strict";var e=function(r,n){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return function(r,n){var t=[],o=!0,e=!1,i=void 0;try{for(var u,f=r[Symbol.iterator]();!(o=(u=f.next()).done)&&(t.push(u.value),!n||t.length!==n);o=!0);}catch(r){e=!0,i=r}finally{try{!o&&f.return&&f.return()}finally{if(e)throw i}}return t}(r,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")},t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},f=function(r,n,t){return n===t?0:n<t?-r:null==n?1:null==t?-1:r},o=function(r,n,t,o,e,i){return c(r(e),r(i),n,t,o,e,i)},i=function(r,n,t,o,e,i){return c(e[r],i[r],n,t,o,e,i)},u=function(r,n,t,o,e,i){var u=r.asc||r.desc,f=r.asc?1:-1;if(!u)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return s(u)(u,n,t,f,e,i)},s=function(r){var n=void 0===r?"undefined":t(r);return"string"===n?i:"function"===n?o:u},c=function(r,n,t,o,e,i,u){return r===n||null==r&&null==n?t.length>o?s(t[o])(t[o],t,o+1,e,i,u):0:f(e,r,n)},a=function(r,n,t){if(!Array.isArray(n))return n;Array.isArray(t)&&t.length<2&&(t=e(t,1)[0]);var o=void 0;return o=t?"string"==typeof t?function(r,n,t,o){return f(r,t[n],o[n])}.bind(void 0,r,t):"function"==typeof t?function(r,n,t,o){return f(r,n(t),n(o))}.bind(void 0,r,t):s(t[0]).bind(void 0,t.shift(),t,0,r):f.bind(void 0,r),n.sort(o)};return function(e){return{asc:function(r){return a(1,e,r)},desc:function(r){return a(-1,e,r)},by:function(r){if(!Array.isArray(e))return e;if(!Array.isArray(r))throw Error("sort: Invalid usage of 'by' sorter. Array syntax is required.\n Did you mean to use 'asc' or 'desc' sorter instead?");if(1===r.length){var n=r[0].asc?1:-1,t=r[0].asc||r[0].desc;if(!t)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return a(n,e,t)}var o=u.bind(void 0,r.shift(),r,0,void 0);return e.sort(o)}}}});
!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r.sort=r.sort||{},r.sort.js=n())}(this,function(){"use strict";var r=function(){function r(r,n){var t=[],o=!0,e=!1,i=void 0;try{for(var u,f=r[Symbol.iterator]();!(o=(u=f.next()).done)&&(t.push(u.value),!n||t.length!==n);o=!0);}catch(r){e=!0,i=r}finally{try{!o&&f.return&&f.return()}finally{if(e)throw i}}return t}return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return r(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},t=function(r,n,t){return n===t?0:n<t?-r:null==n?1:null==t?-1:r},o=function(r,n,o,e){return t(r,o[n],e[n])},e=function(r,n,o,e){return t(r,n(o),n(e))},i=function(r,n,t,o,e,i){return s(r(e),r(i),n,t,o,e,i)},u=function(r,n,t,o,e,i){return s(e[r],i[r],n,t,o,e,i)},f=function(r,n,t,o,e,i){var u=r.asc||r.desc,f=r.asc?1:-1;if(!u)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return c(u)(u,n,t,f,e,i)},c=function(r){var t=void 0===r?"undefined":n(r);return"string"===t?u:"function"===t?i:f},s=function(r,n,o,e,i,u,f){return r===n||null==r&&null==n?o.length>e?c(o[e])(o[e],o,e+1,i,u,f):0:t(i,r,n)},a=function(n,i,u){if(!Array.isArray(i))return i;Array.isArray(u)&&u.length<2&&(u=r(u,1)[0]);var f=void 0;return f=u?"string"==typeof u?o.bind(void 0,n,u):"function"==typeof u?e.bind(void 0,n,u):c(u[0]).bind(void 0,u.shift(),u,0,n):t.bind(void 0,n),i.sort(f)};return function(r){return{asc:function(n){return a(1,r,n)},desc:function(n){return a(-1,r,n)},by:function(n){if(!Array.isArray(r))return r;if(!Array.isArray(n))throw Error("sort: Invalid usage of 'by' sorter. Array syntax is required.\n Did you mean to use 'asc' or 'desc' sorter instead?");if(1===n.length){var t=n[0].asc?1:-1,o=n[0].asc||n[0].desc;if(!o)throw Error("sort: Invalid 'by' sorting onfiguration.\n Expecting object with 'asc' or 'desc' key");return a(t,r,o)}var e=f.bind(void 0,n.shift(),n,0,void 0);return r.sort(e)}}}});
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