Skip to content

A simple JavaScript function that generates an array of page numbers based on the total number of pages, current page and the number of neighbours.

License

Notifications You must be signed in to change notification settings

JoshuwayMorris/simple-page-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Page Numbers

GitHub, NPM

A simple JavaScript/TypeScript function that generates a spread of page numbers, based on the desired spread and the total number of pages.

For example, if you have 53 pages, and your current page is 21, with a spread of 2 pages, the function will output:

{
    "previousPage": 20,
    "nextPage": 21,
    "totalPages": 53,
    "pages": [
        19,
        20,
        21,
        22,
        23
    ]
}

Usage

You can install this package using NPM.

npm install simple-page-numbers --save-dev

Then use the function in your files.

import { paginate } from "simple-page-numbers";
const pagination = paginate(currentPage, totalPages, spread)

License

Distributed under the MIT license.

About

A simple JavaScript function that generates an array of page numbers based on the total number of pages, current page and the number of neighbours.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published