pagination-count-helper
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -8,11 +8,7 @@ module.exports = class PaginationHelper { | ||
itemCount= ()=> this.items.length | ||
// get number of all pages. number of all pages is 1-based. | ||
pageCount= ()=> Math.ceil(this.itemCount()/this.pageLimit) | ||
// get number of items on this (as provided with pageindex argument) page. Page index is 0-based | ||
pageItemCount= pageIndex=> pageIndex< 0 || pageIndex >= this.pageCount()? -1: pageIndex+1< this.pageCount()? this.pageLimit: this.itemCount()%this.pageLimit || this.pageLimit | ||
// get the page number of the page the nth-item will be displayed on. itemIndex and pageIndex are 0-based | ||
pageIndex= itemIndex=> itemIndex+1> this.itemCount() || itemIndex+1 < 1? -1: Math.ceil((itemIndex+1)/this.pageLimit)-1 | ||
} |
const PaginationHelper = require('./index') | ||
test("Count pages, items and items on page 0", ()=> { | ||
const helper = new PaginationHelper(['a','b','c','d','e','f','g','h','i'], 3); | ||
const helper = new PaginationHelper(['a','b','c','d','e','f','g','h'], 3); | ||
expect(helper.pageCount()).toBe(3) | ||
expect(helper.itemCount()).toBe(9) | ||
expect(helper.pageItemCount(0)).toBe(3) | ||
expect(helper.itemCount()).toBe(8) | ||
expect(helper.pageItemCount(2)).toBe(2) | ||
expect(helper.pageIndex(7)).toBe(2) | ||
}) |
{ | ||
"name": "pagination-count-helper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Helper class for page and page item counting", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,6 +7,15 @@ # pagination-count-helper | ||
```js | ||
const helper = new PaginationHelper(['a','b','c','d','e','f','g','h','i'], 3); | ||
const helper = new PaginationHelper(['a','b','c','d','e','f','g','h'], 3); | ||
// retrieve number of pages (1-based) | ||
helper.pageCount() // 3 | ||
helper.itemCount() // 9 | ||
helper.pageItemCount(2) // 3 | ||
// retrieve number of items | ||
helper.itemCount() // 8 | ||
// retrieve number of items on this (as provided by the argument) page (0-based) | ||
helper.pageItemCount(2) // 2 | ||
// retrieve number of the page the specified item will be displayed on (item number and page number are 0-based) | ||
helper.pageIndex(7) // 2 | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3075
20
18