page-slicer
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

page-slicer

Minimal pagination class for JS.

var PageSlicer = require('page-slicer').PageSlicer;
 
var items = 'abcdefghijklmnopqrstuvwxyz'.split('');
var pager = new PageSlicer({ itemsOnPage: 5 }, items);
 
console.log([
  pager.count(), // -> 6
  pager.isValid('5'), // true
  pager.isValid('6'), // false
  pager.isValid('-6'), // true
  pager.isValid('-7'), // false
 
  pager.state, // -> 0
  pager.slice().join(''), // -> 'abcde'
  pager.goNext(),
  pager.slice().join(''), // -> 'fghij'
  pager.goLast(),
  pager.slice().join(''), // -> 'z'
 
  pager.go(-1),
  pager.slice().join(''), // -> 'vwxyz'
  pager.goPrev(),
  pager.slice().join(''), // -> 'qrstu'
  pager.goFirst(),
  pager.slice().join(''), // -> 'a'
].filter(function (x) {
  return typeof x !== 'undefined';
}));

See index.html and index.js for a mithril pagination boilerplate.

Readme

Keywords

Package Sidebar

Install

npm i page-slicer

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

10.6 kB

Total Files

8

Last publish

Collaborators

  • makepost