Package Exports
- do-paginate
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (do-paginate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
paginate
create an array with numbers in incremental order with the current index in the middle of the sequence, and the sequence always being the same length, no matter to index passed in
installation
$ npm install do-paginate
$ yarn add do-paginatetechnologies
- node: 14.16.0
- typescript: 4.2.3
- npm: 6.14.11
- yarn: 1.22.10
code-example
import the pagination -file and pass in your parameters
// typescript
import paginate from 'do-paginate'
const sequence: Array<number> = paginate(1, 25, 1000) // [ 1,2,3,4,5,6,7,8,9,10,11 ] // javascript
const paginate = require('do-paginate')
const sequence = paginate(1, 25, 1000) // [ 1,2,3,4,5,6,7,8,9,10,11 ]the uniqueness of this pagination-method
- sequence is always above 1 and below: content-length / items-per-page
- sequence always makes sense, even if the active page is lower than 1 and higher than: content-length / items-per-page
- sequence is always same length, no matter the index passed in
basic usages
// the first parameter is the active page
paginate(6, 10, 1000) // output: [ 1,2,3,4,5, [6] ,7,8,9,10,11 ]
// the second parameter is the items you want to display per page
paginate(1, 10, 1000) // output: [ [1], 2,3,4,5,6,7,8,9,10,11 ]
// the third parameter is summ of all items
paginate(1, 10, 5000) // output: [ [1], 2,3,4,5,6,7,8,9,10,11 ]
// the fourth parameter is length of the sequence, where length equals: 2 * (offset + 1)
paginate(1, 10, 1000, 7) // output: [ [1], 2,3,4,5,6,7,8,9,10,11,12,13,14,15 ]advanced usages
// lower-bound checking
paginate(1, 10, 1000) // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11 ]
// upper-bound checking
paginate(100, 10, 1000) // [ 90,91,92,93,94,95,96,97,98,99,100 ]
// lower-out-of-bound checking for index
paginate(-10, 10, 1000) // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]
// upper-out-of-bound checking for index
paginate(200, 10, 1000) // [ 90,91,92,93,94,95,96,97,98,99,100 ]
// out-of-bound checking for content length
paginate(1, 10, 25) // [ 1,2,3 ]
// out-of-bound checking for content length and index simultaneously
paginate(-10, 10, 25) // [ 1,2,3 ]
paginate( 10, 10, 25) // [ 1,2,3 ]license
MIT