Sort collections by fields and getters. Inspired by Angular's orderBy filter
npm install orderby
var orderBy = require('orderby');
var collection = [
{age: 100 , name: 'Michael'}
{age: 25 , name: 'Ben'}
{age: 100, name: 'Danny'}
{age: 25, name: 'Max'}
];
// sort by fields
orderBy(collection, ['age', 'name']);
// sort by getters
orderBy(collection, [function(person){ return person.name.length }]);
// reverse each sort individually
orderBy(collection, [
{
predicate: function(person){ return person.name.length },
reverse: true
},
{
predicate: 'age',
reverse: false
}
]);
Please follow our Code of Conduct when contributing to this project.
$ git clone https://github.com/goodeggs/orderby && cd orderby
$ npm install
$ npm test
Module scaffold generated by generator-goodeggs-npm.