Created
March 11, 2022 08:51
-
-
Save WEEFAA/8fc8973c938dec6c22bbbda32ec0c6c5 to your computer and use it in GitHub Desktop.
[Util] Pagination
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 pagination = {} | |
| pagination.process = (page, limit = 10, q = '') => { | |
| try { | |
| page = +page | |
| limit = +limit | |
| // pagination boolean | |
| const paginating = (page && (page === 0 || page > 0)) || false | |
| // get skips | |
| const skips = page <= 1 ? 0 : (page - 1) * limit | |
| return { | |
| paginating, | |
| page, | |
| limit, | |
| skips, | |
| searching: typeof q === 'string' && q !== '', | |
| searchText: String(q), | |
| } | |
| } catch (e) { | |
| throw new Error('Process pagination utility failed ', e.stack) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment