UNPKG

@payfit/unity-components

Version:

40 lines (39 loc) 959 B
//#region src/components/client-side-pagination/utils/pagination-window.ts function e(e, t) { return Array.from({ length: t - e + 1 }, (t, n) => n + e).map((e) => ({ type: "page", value: e })); } var t = 5; function n(n, r, i) { let a = Math.max(t, i % 2 == 0 ? i + 1 : i), o = a - 2; if (n <= a) return Array.from({ length: n }, (e, t) => ({ type: "page", value: t + 1 })); let s = []; s.push({ type: "page", value: 1 }); let c = o - 2, l = Math.floor(c / 2); return r <= 3 + l ? (s.push(...e(2, o)), s.push({ type: "ellipsis", value: [o + 1, n - 1] })) : r >= n - (2 + l) ? (s.push({ type: "ellipsis", value: [2, n - (o - 1) - 1] }), s.push(...e(n - (o - 1), n - 1))) : (s.push({ type: "ellipsis", value: [2, r - l - 1] }), s.push(...e(r - l, r + l)), s.push({ type: "ellipsis", value: [r + l + 1, n - 1] })), s.push({ type: "page", value: n }), s; } //#endregion export { n as generatePaginationWithWindow };