orderby

1.1.0 • Public • Published

orderBy

Sort collections by fields and getters. Inspired by Angular's orderBy filter

build status npm version MIT license we're hiring

Usage

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
  }
]);
 

Contributing

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.

Readme

Keywords

Package Sidebar

Install

npm i orderby

Weekly Downloads

95

Version

1.1.0

License

MIT

Last publish

Collaborators

  • goodeggs-admin