Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

simple-pagination

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-pagination

Just provides only a simple pagination logic

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
227
-22.53%
Maintainers
1
Weekly downloads
 
Created
Source

simple-pagination

npm version Build Status

Just provides only a simple pagination logic

Installation

npm install --save simple-pagination

API

/*
 * Returns pagination result
 *
 * @param {number} totalCount    - Number of items that will be paginated
 * @param {number} perPage       - Number of items per page
 * @param {number} specifiedPage - Page number you wanted to get, it is started by 1
 */
function paginate(totalCount, perPage, specifiedPage) {
};

Examples

var assert = require('assert');
var paginate = require('simple-pagination');

assert.deepEqual(
  paginate(25, 10, 1), {
    totalCount: 25,
    perPage: 10,
    specifiedPage: 1,
    pageCount: 3,
    firstPage: 1,
    lastPage: 3,
    currentPage: 1,
    isFirstPage: true,
    isLastPage: false,
    previousPage: null,
    nextPage: 2,
    fromCount: 1,
    toCount: 10
  }
);

assert.deepEqual(
  paginate(25, 10, 3), {
    totalCount: 25,
    perPage: 10,
    specifiedPage: 3,
    pageCount: 3,
    firstPage: 1,
    lastPage: 3,
    currentPage: 3,
    isFirstPage: false,
    isLastPage: true,
    previousPage: 2,
    nextPage: null,
    fromCount: 21,
    toCount: 25
  }
);

// Specified page number is out of range
assert.deepEqual(
  paginate(25, 10, 4), {
    totalCount: 25,
    perPage: 10,
    specifiedPage: 4,
    pageCount: 3,
    firstPage: 1,
    lastPage: 3,
    // currentPage is different from specifiedPage
    currentPage: 3,
    isFirstPage: false,
    isLastPage: true,
    previousPage: 2,
    nextPage: null,
    fromCount: 21,
    toCount: 25
  }
);

// If page count is 0, then props are mostly null
assert.deepEqual(
  paginate(0, 1, 1), {
    totalCount: 0,
    perPage: 1,
    specifiedPage: 1,
    pageCount: 0,
    firstPage: null,
    lastPage: null,
    currentPage: null,
    isFirstPage: null,
    isLastPage: null,
    previousPage: null,
    nextPage: null,
    fromCount: null,
    toCount: null
  }
);

Keywords

pagination

FAQs

Package last updated on 28 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts