Makes useful calculations for creating website pagination links.
https://www.npmjs.com/package/@pelevesque/paginate
npm install @pelevesque/paginate
Command | Description |
---|---|
npm test or npm run test |
standardx + unit tests |
npm run cover |
unit tests + coverage |
npm run standardx |
standardx |
npm run unit |
unit tests |
const paginate = require('@pelevesque/paginate')
const numLinks = 10 // number of links to others pages
const currentPage = 3
const numItemsPerPage = 10
const numItems = 300
const url = 'http://www.localhost.com/?page='
const paginateObject = paginate(numLinks, currentPage, numItemsPerPage, numItems, url)
// result
paginateObject = {
numLinks: 10,
currentPage: 3,
numItemsPerPage: 10,
numItems: 300,
url: 'www.localhost.com/?page=',
links: [
{ page: 1, active: false, url: 'www.localhost.com/?page=1' },
{ page: 2, active: false, url: 'www.localhost.com/?page=2' },
{ page: 3, active: true, url: 'www.localhost.com/?page=3' },
{ page: 4, active: false, url: 'www.localhost.com/?page=4' },
{ page: 5, active: false, url: 'www.localhost.com/?page=5' },
{ page: 6, active: false, url: 'www.localhost.com/?page=6' },
{ page: 7, active: false, url: 'www.localhost.com/?page=7' },
{ page: 8, active: false, url: 'www.localhost.com/?page=8' },
{ page: 9, active: false, url: 'www.localhost.com/?page=9' },
{ page: 10, active: false, url: 'www.localhost.com/?page=10' },
],
firstPageLink: 1,
lastPageLink: 10,
firstPage: 1,
lastPage: 30,
numPreviousPages: 2,
numFollowingPages: 27,
}
Copyright (c) 2018-2020, Pierre-Emmanuel Lévesque
MIT
Built with ❤︎ by Pierre-Emmanuel Lévesque