Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raulil/sivutin
Simple paginator
https://github.com/raulil/sivutin
django pagination pagination-library
Last synced: about 4 hours ago
JSON representation
Simple paginator
- Host: GitHub
- URL: https://github.com/raulil/sivutin
- Owner: RauliL
- Created: 2021-09-01T21:18:39.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-01T21:48:18.000Z (about 3 years ago)
- Last Synced: 2024-09-26T22:39:47.585Z (about 2 months ago)
- Topics: django, pagination, pagination-library
- Language: TypeScript
- Homepage:
- Size: 50.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sivutin
[![coveralls][coveralls-image]][coveralls-url]
[![npm][npm-image]][npm-url][coveralls-image]: https://coveralls.io/repos/github/RauliL/sivutin/badge.svg
[coveralls-url]: https://coveralls.io/github/RauliL/sivutin
[npm-image]: https://img.shields.io/npm/v/sivutin.svg
[npm-url]: https://npmjs.org/package/sivutinVery simple paginator.
## Installation
```sh
$ npm install --save sivutin
```## Usage
The library consists from a single function, which looks like this:
```typescript
paginate(
// Any array like object to be paginated.
container: ArrayLike,// Selected page number.
page: number = 1,// Number of results per page.
pageNumber: number = 10
)
```And it returns an object like this:
```typescript
{
// Array of results for the page.
results: Array;// Total number of results.
count: number;// Next page index, or null if this is the last page in results.
next: number | null;// Previous page index, or null if this is the first page in results.
previous: number | null;
}
```Usage of the function looks like this:
```javascript
import paginate from 'sivutin';const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
paginate(numbers, 1, 5).results; //=> [1, 2, 3, 4, 5]
paginate(numbers, 2, 5).results; //=> [6, 7, 8, 9, 10]
```