1.0.3 • Published 2 years ago

ellipsis-pagination v1.0.3

Weekly downloads
122
License
ISC
Repository
github
Last release
2 years ago

Ellipsis Pagination

The purpose of this package is to help frontend to generate a pagination with ellipsis


Installation

yarn

yarn add ellipsis-pagination

npm

npm install ellipsis-pagination

Usage

Example

import truncatePagination from 'ellipsis-pagination'

const paginate = truncatePagination({
  prefix: 2, // optional, default is 2
  suffix: 2, // optional, default is 2
  currentPage: 1, // required
  displayNumber: 5, // required, number of pager to display
  totalPage: 10 // required
})

Parameters

ParamsTypeDescriptionDefaultRequired
prefixintNumber cannot greater than 22
suffixintNumber cannot greater than 22
currentPageintcurrent number page-
displayNumberintNumber must be higher than 3 and must be an odd number-
totalPageinttotal number of pages-

Sample Result

[
   {
      "type":"PAGE",
      "page":1,
      "isActive":true
   },
   {
      "type":"PAGE",
      "page":2,
      "isActive":false
   },
   {
      "type":"PAGE",
      "page":3,
      "isActive":false
   },
   {
      "type":"PAGE",
      "page":4,
      "isActive":false
   },
   {
      "type":"PAGE",
      "page":5,
      "isActive":false
   },
   {
      "type":"ELLIPSIS",
      "page":"suffix-ellipsis",
      "isActive":false
   },
   {
      "type":"PAGE",
      "page":9,
      "isActive":false
   },
   {
      "type":"PAGE",
      "page":10,
      "isActive":false
   }
]
NameDescriptionValue
typetype of paginationPAGE or ELLIPSIS
pagepage numberint
isActivecurrent pageint

ToDo

  • Unit test
  • Typescript