@vlsergey/react-bootstrap-pagination
Version:
Ready-to-use wrapper for react-bootstrap Pagation component
40 lines (39 loc) • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function calcLinksToDisplay(totalPages, currentPage, atBeginEnd, aroundCurrent, ellipsisMark) {
var result = [];
for (var page = 0; page < (totalPages === undefined ? atBeginEnd : Math.min(atBeginEnd, totalPages)); page++) {
if (!result.includes(page))
result.push(page);
}
if (result.length !== 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
var lastInLinks = result[result.length - 1];
if (lastInLinks < Math.max(currentPage - aroundCurrent, 0) - 1)
result.push(ellipsisMark);
}
else if (Math.max(currentPage - aroundCurrent, 0) > 0)
result.push(ellipsisMark);
for (var page = Math.max(currentPage - aroundCurrent, 0); page <= (totalPages === undefined ? currentPage + aroundCurrent : Math.min(currentPage + aroundCurrent, totalPages - 1)); page++) {
if (!result.includes(page))
result.push(page);
}
if (totalPages !== undefined) {
if (result.length !== 0) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
var lastInLinks = result[result.length - 1];
if (lastInLinks < Math.max(totalPages - atBeginEnd, 0) - 1
&& lastInLinks !== ellipsisMark) {
result.push(ellipsisMark);
}
}
if (totalPages !== undefined && totalPages !== Number.POSITIVE_INFINITY) {
for (var page = Math.max(totalPages - atBeginEnd, 0); page <= totalPages - 1; page++) {
if (!result.includes(page))
result.push(page);
}
}
}
return result;
}
exports.default = calcLinksToDisplay;