Skip to content

pelevesque-node/paginate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paginate

Makes useful calculations for creating website pagination links.

Node Repository

https://www.npmjs.com/package/@pelevesque/paginate

Installation

npm install @pelevesque/paginate

Tests

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

Usage

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,
}

Integration with Adonis.js

adonisjs/core#1381

Copyright

Copyright (c) 2018-2020, Pierre-Emmanuel Lévesque

License

MIT

Built with ❤︎ by Pierre-Emmanuel Lévesque

About

Makes useful calculations for creating website pagination links.

Resources

License

Stars

Watchers

Forks

Packages

No packages published