1.1.0 • Published 11 years ago
connect-pagination v1.1.0
connect-pagination
Very simple and easy to use connect (express) middleware for parsing pagination query strings.
Installation
$ npm install connect-paginationQuick Start with Connect.js or Express.js
var connect = require('connect'),
pagination = require('connect-pagination')
var paginationOptions = {
pageParam: 'p'
};
connect()
.use(pagination(options))
.use(function (req, res) {
res.send(req.pagination);
});Available Options
pageParamspecifies the query param for the page number (defaults topage)ippParamspecifies the query param for the number of items per page (defaults toipp)pagethe default page number (defaults to1)ippthe default number of items per page (defaults to24)
The req.pagination object
Through req.pagination the following object becomes available:
pagethe current requested page numberpipthe current requested number of items per pageoptionsPresenttrueif there are pagination request parameters- Function
buildQuery(page, ipp)returns a query string like?page=4&ipp=20 - Function
addQuery(url, page, ipp)adds the pagination query to the url given
Changelog
1.1.0
May not be backwards-compatible.
- Now builds the query string with the parameter names given.
1.0.5
- Fixed bug that resulted in wrong query strings.
1.0.4
- Add
optionsPresentattribute toreq.paginationobject.
1.0.3
- Parse query parameters to numbers.
1.0.2
- The
paginationobject is now attached tores.localsso that it can be used in express remplates