paginator-walker
v0.1.0
Published
Simple pages-numbers array generator
Downloads
1
Readme
Paginator walker
Simple pages-numbers array generator.
Generates what pages numbers you should show, based on current page position and total pages, with custom threshold and number of pages to show.
With the default config params, from page 1 to page 4 generates [1, 2, 3, 4, 5]
, for page 5 it will walk and show [2, 3, 4, 5, 6]
; if custom threshold config is in use, page 4 will start the walk [2, 3, 4, 5, 6]
(threshold with value of 2).
Usage
const walker = require('pages-walker')
const currentPage = 1 // dynamic value from user
const totalPages = 10 // total pages from pagination
const pages = walker(currentPage, totalPages)
// pages -> [1,2,3,4,5] - 5 pages by default
Params
- currentPage:1: Current page to calculate prev/next pages.
- totalPages:5: Total pages from your pagination results.
- Configuration:{ threshold: 1, showPages: 5 }: Configuration object for threshold and pages to generate.