/
MariaTsys
/
courseworkPP
Обзор
Документация
Войти
/
MariaTsys
/
courseworkPP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/app/lib/utils.ts
29 строк
1 KB
Maria
first_commit
09 май 2025, 12:17
09 май 2025, 12:17
af55308
Код
Авторство
О чём код?
export const generatePagination = (currentPage: number, totalPages: number) => { // If the total number of pages is 7. // display all pages without any ellipsiess, if (totalPages <= 7) { return Array.from({ length: totalPages }, (_, i) => i + 1); } // If the current page is among the first 3 pages, // show the first 3, an ellipsis, and the last 2 pages. if (currentPage <= 3) { return [1, 2, 3, '...', totalPages - 1, totalPages]; } // If the current page is among the last 3 pages, // show the first 2, an ellipsis, and the last 3 pages. if (currentPage >= totalPages - 2) { return [1, 2, '...', totalPages - 2, totalPages - 1, totalPages]; } // If the current page is somewhere in the middle, // show the first page, an ellipsis, the current page and its neighbors, // another ellipsis, and the last page. return [ 1, '...', currentPage - 1, currentPage, currentPage + 1, '...', totalPages, ] }