1.0.0 • Published 7 years ago
pagesify v1.0.0
pagesify
Simple pagination algorithm
Requirements
- node.js
Install
$ npm install --save pagesify
Usage
var Pagesify = require('pagesify');
var pagesify = new Pagesify({
interval: 3,
placeholder: '..',
itemsPerPage: 3
});
var items = [
'radiohead',
'jamie woon',
'actress',
'joy division',
'burial',
'sampha',
'the xx',
'nicolas jaar',
'boards of canada',
'james blake',
'nicolas jaar'
];
var currentPage = 3;
var pagination = pagesify.paginate(items, currentPage);
console.log(pagination.handles);
// { handles: [ 'prev', 1, 2, 3, '..', 4, 'next' ] }
console.log(pagination.pages);
/* pages:
{ '1': [ 'radiohead', 'jamie woon', 'actress' ],
'2': [ 'joy division', 'burial', 'sampha' ],
'3': [ 'the xx', 'nicolas jaar', 'boards of canada' ],
'4': [ 'james blake', 'nicolas jaar' ],
length: 4 } }
*/
API
- createPageHandles
- convertListToPages
createPageHandles (pages, currentPage)
pages: object starting from 1
currentPage: number
Returns an array of handles
convertListToPages (list, itemsPerPage)
list: object starting from 1
itemsPerPage: number
Returns an object of pages
License
MIT © Ricardo Matias
1.0.0
7 years ago