Created
November 24, 2021 07:48
-
-
Save fronterior/89442de31e87750b1118204b38658222 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createRangePagination = (page: number, limit: number, total: number, range: number) => { | |
const size = range * 2 + 1; | |
const maxPage = Math.ceil(total / limit); | |
const start = range >= page ? 1 | |
: maxPage - range < page ? maxPage - size + 1 | |
: page - range; | |
const end = size > page + range ? size | |
: maxPage < page + range ? maxPage | |
: page + range; | |
return Array.from({length: end - start + 1}, (_, i) => i + start); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment