Package Exports
- page-hopper
- page-hopper/src/paginate.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (page-hopper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
page-hopper
A simple and efficient pagination utility for arrays in JavaScript, suitable for both Node.js and browser environments.
Installation
npm install page-hopperUsage
Basic Usage
const paginate = require('page-hopper');
const collection = [/* your array data */];
const pageNumber = 1;
const numItemsPerPage = 10;
const paginatedCollection = paginate(collection, pageNumber, numItemsPerPage);
console.log(paginatedCollection);This will output:
{
currentPage: 1,
perPage: 10,
total: 30,
totalPages: 3,
data: [/* paginated items */]
}With Custom Options
const customOptions = { customKey: 'customValue' };
const paginatedCollection = paginate(collection, pageNumber, numItemsPerPage, customOptions);
console.log(paginatedCollection);This will output:
{
currentPage: 1,
perPage: 10,
total: 30,
totalPages: 3,
data: [/* paginated items */],
customKey: 'customValue'
}Features
- Simple and easy to use.
- No external dependencies.
- Customizable pagination.