@acyort/paginator

Pagination utilities

Usage no npm install needed!

<script type="module">
  import acyortPaginator from 'https://cdn.skypack.dev/@acyort/paginator';
</script>

README

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 } ]
*/