https://github.com/acyortjs/paginator
Pagination utilities
https://github.com/acyortjs/paginator
Last synced: about 1 month ago
JSON representation
Pagination utilities
- Host: GitHub
- URL: https://github.com/acyortjs/paginator
- Owner: acyortjs
- License: mit
- Created: 2018-01-13T09:26:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-12T13:09:30.000Z (over 7 years ago)
- Last Synced: 2025-08-16T14:37:40.768Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Paginator
[](https://travis-ci.org/acyortjs/paginator)
[](https://codecov.io/gh/acyortjs/paginator)
pagination utilities
## Install
```bash
$ npm i @acyort/paginator -S
```
## Usage
```js
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 } ]
*/
```