Skip to content

Instantly share code, notes, and snippets.

@WEEFAA
Created March 11, 2022 08:51
Show Gist options
  • Select an option

  • Save WEEFAA/8fc8973c938dec6c22bbbda32ec0c6c5 to your computer and use it in GitHub Desktop.

Select an option

Save WEEFAA/8fc8973c938dec6c22bbbda32ec0c6c5 to your computer and use it in GitHub Desktop.
[Util] Pagination
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