mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 01:22:49 +00:00
31 lines
660 B
TypeScript
31 lines
660 B
TypeScript
export const pagination = (page: number, numPages: number): (number | string)[] => {
|
|
const current = page;
|
|
const last = numPages;
|
|
const delta = 2;
|
|
const left = current - delta;
|
|
const right = current + delta + 1;
|
|
const range = [];
|
|
const rangeWithDots = [];
|
|
let l;
|
|
|
|
for (let i = 1; i <= last; i++) {
|
|
if (i === 1 || i === last || (i >= left && i < right)) {
|
|
range.push(i);
|
|
}
|
|
}
|
|
|
|
for (const i of range) {
|
|
if (l) {
|
|
if (i - l === 2) {
|
|
rangeWithDots.push(l + 1);
|
|
} else if (i - l !== 1) {
|
|
rangeWithDots.push('...');
|
|
}
|
|
}
|
|
rangeWithDots.push(i);
|
|
l = i;
|
|
}
|
|
|
|
return rangeWithDots;
|
|
};
|