Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

chopchop

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chopchop

(wip) easy paging for web apps

latest
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

chopchop

(wip) easy paging for web apps

usage

var chopchop = require('chopchop')

// assuming an express app
app.get('/foos',
  chopchop(),
  function (req, res) {
    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

api

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()

installation

$ npm install chopchop

running the tests

From package root:

$ npm install
$ npm test

contributors

license

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

Keywords

paging

FAQs

Package last updated on 17 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts