Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/deiucanta/pagelist

Pagination logic/algorithm in Javascript
https://github.com/deiucanta/pagelist

algorithm javascript pagelist pagination paginator typescript

Last synced: 4 days ago
JSON representation

Pagination logic/algorithm in Javascript

Awesome Lists containing this project

README

        

# Pagelist

## Install

```
npm install pagelist
```

```
yarn add pagelist
```

## Usage

```js
import { pagelist } from 'pagelist';

const current = 1;
const total = 500;
const display = 9;

pagelist(current, total, display);
// => 1, 2, 3, 4, 5, 6, 7, _, 500
```

## Examples

| Current | Total | Display | Result |
| ------- | ----- | ------- | --------------------------------------- |
| 1 | 1 | 10 | `[1]` |
| 1 | 10 | 10 | `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` |
| 2 | 10 | 10 | `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]` |
| 1 | 1000 | 10 | `[1, 2, 3, 4, 5, 6, 7, 8, '-', 1000]` |
| 5 | 1000 | 10 | `[1, 2, 3, 4, 5, 6, 7, 8, '-', 1000]` |
| 6 | 1000 | 10 | `[1, '-', 4, 5, 6, 7, 8, 9, '-', 1000]` |
| 500 | 1000 | 7 | `[1, '-', 499, 500, 501, '-', 1000]` |
| 1000 | 1000 | 7 | `[1, '-', 996, 997, 998, 999, 1000` |
| 995 | 1000 | 7 | `[1, '-', 994, 995, 996, '-', 1000]` |