All files / src/shared/components/Paginator getVisiblePages.ts

100% Statements 14/14
100% Branches 3/3
100% Functions 1/1
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 191x 101x   101x 101x 101x   101x 76x 76x 76x   101x 199x 199x   101x 101x  
export const getVisiblePages = (currentPage: number, totalPages: number, maxVisiblePages: number): number[] => {
  const pages = [];
 
  const half = Math.floor(maxVisiblePages / 2);
  let start = Math.max(currentPage - half, 1);
  let end = start + maxVisiblePages - 1;
 
  if (end > totalPages) {
    end = totalPages;
    start = Math.max(end - maxVisiblePages + 1, 1);
  }
 
  for (let i = start; i <= end; i++) {
    pages.push(i);
  }
 
  return pages;
};