Created
January 14, 2017 16:22
-
-
Save jstott/7b50d4f4790c357227bafd13b4ef32a4 to your computer and use it in GitHub Desktop.
lodash paginated items
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
function getPaginatedItems(items, page, pageSize) { | |
var pg = page || 1, | |
pgSize = pageSize || 100, | |
offset = (pg - 1) * pgSize, | |
pagedItems = _.drop(items, offset).slice(0, pgSize); | |
return { | |
page: pg, | |
pageSize: pgSize, | |
total: items.length, | |
total_pages: Math.ceil(items.length / pgSize), | |
data: pagedItems | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment