simple-pager is the small and simple pager library for node. It doesn't do any rendering instead it generates data model you can use in any way in your with your template engine or with any other tools.
npm install simple-pager
var pager = require('simple-pager');
var pagesModel = pager.getPagesModel(4, 10);
The pagesModel will look like this:
[
{ page: 3 },
{ page: 4, current: true },
{ page: 5 }
]
The first page number is 1. Zero page is considered to be out of the valid pages range.
In fact getPagesModel is the only method exposed by the module:
getPagesModel(currentPage, totalPages [, options])
If you don't pass any options by default this method generates a list with the current page and couple of surrounding pages. The first, the last and current page will be marked by the corresponding boolean property. Here is the full set of the available options with default values:
{
surroundWith: 1,
outputFirst: false,
outputLast: false
}
surroundWith
- number of pages to output before and after the currentoutputFirst
- whether the first page should be present in the result arrayoutputLast
- whether the last page should be present in the result array