https://github.com/aboutbits/pagination
https://github.com/aboutbits/pagination
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aboutbits/pagination
- Owner: aboutbits
- License: mit
- Created: 2020-08-06T06:34:04.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-09-11T05:47:52.000Z (5 months ago)
- Last Synced: 2025-09-11T08:54:45.467Z (5 months ago)
- Language: TypeScript
- Homepage:
- Size: 542 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
Pagination
==========
[](https://badge.fury.io/js/%40aboutbits%2Fpagination)
[](https://github.com/aboutbits/pagination/blob/master/license.md)
This pagacke includes a pagination calculation, where you can simply pass some basic information to the calcualtion function, and in return you receive an object with all relevant pagination information.
## Table of content
- [Usage](#usage)
- [Build & Publish](#build--publish)
- [Information](#information)
## Usage
First, you have to install the package:
```bash
npm install @aboutbits/pagination
```
Second, you can call the calculate function by passing the following information:
- `page`: The current page
- `size`: The amount of items shown per page
- `total`: The amount of total items in the list/collection
- `config`: A configuration object containing the following possible configuration values:
- `indexType`: The starting point of the pagination (default: IndexType.ONE_BASED)
- `maxPages`: The maximum amount of pages that should be shown (default: 5)
In return, you receive an object with all relevant information:
```js
import { calculatePagination } from '@aboutbits/pagination'
let pagination = calculatePagination(1, 5, 100)
console.log(pagination)
```
This would return the following object:
```json
{
"previous": {
"indexNumber": 1,
"isDisabled": true
},
"next": {
"indexNumber": 2,
"isDisabled": false
},
"pages": [
{
"indexNumber": 1,
"displayNumber": 1,
"isCurrent": true
},
{
"indexNumber": 2,
"displayNumber": 2,
"isCurrent": false
},
{
"indexNumber": 3,
"displayNumber": 3,
"isCurrent": false
},
{
"indexNumber": 4,
"displayNumber": 4,
"isCurrent": false
},
{
"indexNumber": 5,
"displayNumber": 5,
"isCurrent": false
}
]
}
```
## Build & Publish
To build and publish the package, visit the GitHub Actions page of the repository.
You can choose between two workflows:
- `Release Package` to publish a new version of the package.
- `Pre-Release Package` to publish a new pre-release version of the package.
**Note:** Pre-releases need to be supplied with a pre-id.
**Note:** To increment a pre-release, you have to run the normal release workflow and select "prerelease". For this action you need to already be on a pre-release version.
## Information
About Bits is a company based in South Tyrol, Italy. You can find more information about us on [our website](https://aboutbits.it).
### Support
For support, please contact [info@aboutbits.it](mailto:info@aboutbits.it).
### Credits
- [Alex Lanz](https://github.com/alexlanz)
- [Martin Malfertheiner](https://github.com/mmalfertheiner)
- [All Contributors](../../contributors)
### License
The MIT License (MIT). Please see the [license file](license.md) for more information.