Generic pagination algorithm wrapped in a CommonJS module
Generic pagination algorithm wrapped in a CommonJS module.
When developing any kind of application that involves fetching an arbitrary number of elements from somewhere, you'll almost always want some form of pagination. It's impossible to tell in advance how the rest of the application will work, so a generic module that does -only- the pagination algorithm is useful. Enter Paginator.
Also see the documentation.
var Paginator = require"paginator";// Arguments are `per_page` and `length`. `per_page` changes the number of// results per page, `length` changes the number of links displayed.var paginator = 30 7;// Arguments are `total_results` and `current_page`. I hope these are self// explanatory.var pagination_info = paginatorbuild10000 50;// The returned object will look something like this.total_pages: 334current_page: 50first_page: 46last_page: 53previous_page: 49next_page: 51has_previous_page: truehas_next_page: truetotal_results: 10000results: 30first_result: 1470last_result: 1499
Licensed under an MIT license.