Comparing version 1.2.8 to 1.3.0
@@ -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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8999
100