Skip to content

drikusroor/koko-pagination-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Koko pagination numbers

A function to generate page numbers with dots in between for navigational purposes.

All credits go to sarifconrati who provided the gist. See also this gist (original by kottenator for other implementations of this algorithm and for translations to other programming languages.

Installation

Install using npm or yarn

npm install koko-pagination-numbers

or

yarn add koko-pagination-numbers

Usage

The first parameter is the current page. The second parameter is the last page. The third (optional) parameter is the width, or the amount of page numbers between the dots and the current page number (default = 2).

const getPageNumbers = require("koko-pagination-numbers");

const pageNumbers = getPageNumbers(7, 30);
// returns [1, "...", 5, 6, 7, 8, 9, "...", 30]

const widerPageNumbers = getPageNumbers(15, 30, 4);
// returns [1, "...", 11, 12, 13, 14, 15, 16, 17, 18, 19, "...", 30]

About

A function to generate page numbers with dots for navigation purposes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published