Created
August 16, 2023 00:02
-
-
Save russo97/f7141348c8f13f970ad16dd448b273e3 to your computer and use it in GitHub Desktop.
generate a clamp for a range of page indexes
This file contains 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 clampedPaginatedIndex = computed(() => { | |
const page = parseInt(response.products?.page ?? 1); | |
const lastPage = response.products?.last_page ?? 1; | |
const clampRange = Math.min(5, lastPage); | |
const offset = Math.max(0, Math.min(page - Math.ceil(clampRange / 2), lastPage - clampRange)); | |
return Array.from({ length: clampRange }, (_, index) => offset + index + 1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment