Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2.8 to 1.3.0

2

package.json

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

{"name":"fast-sort","version":"1.2.8","description":"Blazing fast array sorting.","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.3.0","description":"Blazing fast array sorting.","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"]}

@@ -39,12 +39,26 @@ # fast-sort

// Sort persons [Object] ascending by lowercase firstName
sort(persons).asc((p) => p.firstName.toLowerCase());
// Sort persons [Object] ascending by firstName
sort(users).asc(u => u.firstName);
// Sort persons by multiple properties
sort(persons).desc([
(p) => p.firstName, // Sort by first name
(p) => p.lastName, // Persons that have same firstName will be sorted by lastName
(p) => p.dob // Persons that have same firstName and lastName will be sorted by dob
// Same as above (but bit more performant)
// NOTE: sorting by string is avaliable from version [1.3.0]
sort(users).asc('firstName');
// If we wan't to sort by nested property we need to provide sort function
// String alternative is only available for root level properties
sort(users).desc(u => u.address.city);
// Sort users by multiple properties
sort(users).desc([
'firstName', // Sort by first name
'lastName', // Persons that have same firstName will be sorted by lastName
u => u.address.city // NOTE: For nested properties we have to use function as 'address.city' is not valid property
]);
// Sort by any custom logic e.g sort vip users first
sort(users).asc([
u => u.tags === 'vip' ? 1 : -1, // Sort users that have vip tag to the top
u => u.firstName // users with vip tag will be sorted by firstName
])
// Sorting values that are not sortable will return same value back

@@ -51,0 +65,0 @@ sort(null).asc(); // => null

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