npm install pagination-calculator
Note: the package includes typings for Typescript
import { paginationCalculator } from "pagination-calculator";
const options = {
// see below
};
const result = paginationCalculator(options);
interface PageCalculatorOptions {
total: number; // total number of items
current?: number; // current page - default 1
pageSize?: number; // number of items per page - default 10
pageLimit?: number; // number of pages in array - default no limit
}
interface PageInformation {
total: number; // total number of items
current: number; // current page
pageCount: number; // total number of pages
pages: (number | "...")[]; // array of page numbers
next: number | false; // next page or false if end
previous: number | false; // previous page or false if first
showingStart: number; // index of first item showing on current page
showingEnd: number; // index of last item showing on current page
}