Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pagination-count-helper

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination-count-helper - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

4

index.js

@@ -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
}

7

index.test.js
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
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc