UNPKG

vinmonopolet-ts

Version:

Extracts information on products, categories and stores from Vinmonopolet

53 lines (52 loc) 1.35 kB
class Pagination { /** * The current page of the results. */ currentPage; /** * The number of results in each page. */ pageSize; /** * The total number of pages in the response. */ totalPages; /** * The total number of items in the response. */ totalResults; /** * Is true if there are more pages. */ hasNext; /** * Is true if there previous pages. */ hasPrevious; /** * A string of the sort options used. */ sort; fetcher; options; constructor(paging, options, fetcher) { this.currentPage = paging.currentPage; this.pageSize = paging.pageSize; this.totalPages = paging.totalPages; this.totalResults = paging.totalResults; this.hasNext = paging.currentPage < this.totalPages; this.hasPrevious = paging.currentPage > 0; this.sort = paging.sort; this.fetcher = fetcher; this.options = options; } next() { return this.fetcher(Object.assign({}, this.options, { page: this.options.page + 1 })); } previous() { return this.fetcher(Object.assign({}, this.options, { page: Math.max(0, this.options.page - 1), })); } } export default Pagination;