chopchop

(wip) easy paging for web apps

chopchop

(wip) easy paging for web apps

var chopchop = require('chopchop')
 
// assuming an express app 
app.get('/foos',
  chopchop(),
  function (reqres) {
    console.log(req.paging)
    // => { 
    //  defaultLimit: 10, 
    //  maxLimit: 50, 
    //  skip: 0, 
    //  limit: 10, 
    //  pageNumber: 1, 
    //  sort: undefined, 
    //  sortOrder: 1 
    // } 
 
  }
)

chopchop parses querystring parameters:

  • limit
  • skip
  • sort: property name to sort by
  • sortOrder: asc or desc, gets parsed as 1 for asc, -1 for desc

chopchop: (opts?: Object) => ConnectMiddleware

options:

  • defaultLimit: Int
  • maxLimit: Int
  • sortable: Array - whitelisted property names that are sortable
  • defaultSort: String - default sort property

chopchop.query: (req: Object, query: MinqQuery) => MinqQuery

if you've got a minq Query, say, you can inject all of your paging parameters into it with this method. req should be the HttpRequest object after being banged up a bit by the chopchop middleware. Example:

var pagedQuery = chopchop(req,
  minq.from('users')
      .where({'active':true})
  )
  .toArray()
$ npm install chopchop

From package root:

$ npm install
$ npm test

MIT. (c) 2013 jden jason@denizac.org. See LICENSE.md