Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yeisontapia/paginatejson
📖📖 Small function for paginate arrays in JavaScript. 🧐
https://github.com/yeisontapia/paginatejson
array function javascript json jsonpaginate page paginate paginatejson utils utils-lib
Last synced: 2 months ago
JSON representation
📖📖 Small function for paginate arrays in JavaScript. 🧐
- Host: GitHub
- URL: https://github.com/yeisontapia/paginatejson
- Owner: YeisonTapia
- Created: 2020-01-28T22:45:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T19:40:08.000Z (about 2 years ago)
- Last Synced: 2024-04-26T03:02:52.383Z (8 months ago)
- Topics: array, function, javascript, json, jsonpaginate, page, paginate, paginatejson, utils, utils-lib
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/paginatejson
- Size: 104 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# paginateJson 📖
This small library allows you to easily page an array.
### Install
```
npm i paginatejson
```### Arguments:
* array: Array that needs to be paginated.
* page: Page you need to access.
* perPage: Number of records per page.### Example Use
```js
let paginatejson = require('paginatejson')let posts = [
{
"id": 1,
"title": "One",
"author": "I"
},
{
"id": 2,
"title": "two",
"author": "I"
},
{
"id": 3,
"title": "three",
"author": "I"
},
{
"id": 4,
"title": "three",
"author": "I"
},
{
"id": 5,
"title": "three",
"author": "I"
},
{
"id": 6,
"title": "three",
"author": "I"
},
{
"id": 7,
"title": "three",
"author": "I"
},
{
"id": 8,
"title": "three",
"author": "I"
},
{
"id": 9,
"title": "three",
"author": "I"
}
]let result = paginatejson.paginate(posts, 1, 5)
console.log(result)
/*
{
items: [
{ id: 1, title: 'One', author: 'I' },
{ id: 2, title: 'two', author: 'I' },
{ id: 3, title: 'three', author: 'I' },
{ id: 4, title: 'three', author: 'I' },
{ id: 5, title: 'three', author: 'I' }
],
next: 2,
current: 1,
first: 1,
last: 2
}
*/```