Pagination utilities
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.editorconfig
.eslintrc
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

Paginator

Build Status codecov

pagination utilities

Install

$ npm i @acyort/paginator -S

Usage

const paginator = require('@acyort/paginator')

let data = {
  base: '/xxx/yyy',             // base url
  perpage: 0,                   // per page
  posts: [1, 2, 3, 4, 5],       // posts data
  prefix: 'nav'                 // page prefix, default 'page'
}

const extra = { title: 'zzz' }  // extra data

paginator(data, extra)
/*
[ { base: '/xxx/yyy',
    title: 'zzz',
    prev: '',
    next: '',
    posts: [ 1, 2, 3, 4, 5 ],
    currentPath: '/xxx/yyy',
    current: 1,
    total: 1, type: 'index' } ]
*/

data = {
  base: '/',
  perpage: 2,
  posts: [1, 2, 3, 4, 5],
}

paginator(data)
/*
[ { base: '/',
    prev: '',
    next: '/page/2/',
    posts: [ 1, 2 ],
    currentPath: '/',
    current: 1,
    total: 3 },
  { base: '/',
    prev: '/',
    next: '/page/3/',
    posts: [ 3, 4 ],
    currentPath: '/page/2',
    current: 2,
    total: 3 },
  { base: '/',
    prev: '/page/2/',
    next: '',
    posts: [ 5 ],
    currentPath: '/page/3',
    current: 3,
    total: 3 } ]
*/