pagina

1.0.0 • Public • Published

pagina

NPM version build status Codecov

Paginate any collection and add links to the next/prev page.

Features

  • converts a response body containing a JSON array into a pagination object
  • no need to modify existing route handlers
  • works independently of your datastore, convenient for small datasets loaded into memory

Install

npm install pagina --save

Examples

const express = require('express');
const app = express();
const paginate = require('pagina');

// without pagination

app.get('/items', (req, res, next) => {
  Item
    .find({ owner: req.user })
    .then(items => res.status(200).json(items))
}); 
  
// [1, 2, 3, 4]

// with pagination

// query params override options
const options = { start: 0, limit: 3 }; 

app.get('/items', paginate(options), (req, res, next) => {
  Item
    .find({ owner: req.user })
    .then(items => res.status(200).json(items))
}); 
  
// { 
//   "items": [1, 2, 3], 
//   "prev": null,
//   "next": "http://localhost/items?start=3&limit=3"
// }

License

MIT

TODO

http://tools.ietf.org/html/rfc5988#page-6

Package Sidebar

Install

npm i pagina

Weekly Downloads

20

Version

1.0.0

License

MIT

Last publish

Collaborators

  • amorenoc