page-numbers

This is a stateless page number generator.
The purpose of this package is only to generate a list
of items to be displayed in a pagination control.
Maintaining state, rendering of the actual control and presentation to the user is out of scope.
Get it
yarn add page-numbers
Use it
Hello world
import pager from 'page-numbers';
const total = 5;
const current = 2;
const pages = pager(total, current);
console.log(pages.toString())
console.log(JSON.stringify(pages))
With default options
const options = {
target: 15,
neighbours: {
edge: 1,
current: 2,
},
focus: undefined,
}
const pages = pager(100, 19, options);
console.log(pages.toString())
console.log(JSON.stringify(pages))
With a focus region
If a gap region from the previous example is passed to the pager method
in the options.focus
property, it will include more items in that region.
const pages = pager(100, 19);
const gap = pages[2];
const focusedPages = pager(100, 19, { focus: gap })
console.log(pages.toString())
console.log(JSON.stringify(pages))
API
Imports
import { Item, Options, Neighbours } from 'page-numbers';
import { GapItem, NumberItem } from 'page-numbers';
import pager from 'page-numbers';
Method signature
Item[] pager(
total : number,
current : number,
options : Options
)
Types
All public types are here.
The types are bundled with the project, so you can import
the module directly into your TypeScript project.
Develop it
yarn
yarn build
yarn test
yarn coverage