Move getPageIndex to utils, add tests

This commit is contained in:
Vadim
2021-01-27 21:22:46 +03:00
parent 0bdb14cbf3
commit fa8a25c81f
3 changed files with 27 additions and 3 deletions

View File

@@ -23,3 +23,7 @@ export function getPrevPageIndexInfinte(currentPageIndex, pagesCount) {
export function getPrevPageIndexFn(infinite) {
return infinite ? getPrevPageIndexInfinte : getPrevPageIndexLimited
}
export function getPageIndex(pageIndex, pagesCount) {
return pageIndex < 0 ? 0 : Math.min(pageIndex, pagesCount - 1)
}