koko-pagination-numbers

1.0.0 • Public • Published

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]

Package Sidebar

Install

npm i koko-pagination-numbers

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.91 kB

Total Files

4

Last publish

Collaborators

  • drikusroor