1.0.4 • Published 4 years ago

paginate-info v1.0.4

Weekly downloads
492
License
MIT
Repository
github
Last release
4 years ago

paginate-info

A simple module to paginate your arrays and calculate limit and offset

const { calculateLimitAndOffset, paginate } = require('paginate-info')

const { limit, offset } = calculateLimitAndOffset(2, 20)

// limit = 20, offset = 20

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

Installation is done using the npm install command:

$ npm install paginate-info

Features

  • calculate limit and offset
  • generate pagination info
  • calculates total number of pages.

API

  • calulateLimitAndOffset

    calculates the offset and limit

ParamsTypeDescription
currentPagenumbercurrentPage to get, defaults to 1
pageLimit(optional)numbermaximum number of items to return for the current page, defaults to 20

| Returned Object:

ParamsTypeDescription
offsetnumbernumber of items to skip or offset
limitnumbermaximum number of items to return for the current page, defaults to 20

|

  • paginate

    returns the pagination info

ParamsTypeDescription
currentPagenumbercurrentPage to get, defaults to 1
countnumbertotal count of items, probably gotten from database query
rowsarrayarray of items to paginate
pageLimit(optional)numbermaximum number of items to return for the

|

Returned Object

ParamsTypeDescription
currentPagenumbercurrentPage to get, defaults to 1
pageCountnumbertotal count of available pages
pageSizenumbertotal number of items returned in the current page
countnumbermaximum number of items to return for the query

|

Examples

You can checkout examples while using mongoose for mongoDb or sequelize for SQL or postgreSQL here