Skip to content

Commit 1253695

Browse files
committed
Readme and license
1 parent 21abc90 commit 1253695

4 files changed

Lines changed: 110 additions & 14 deletions

File tree

license.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright About Bits GmbH
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

readme.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
11
Pagination
22
==========
33

4+
This project 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.
5+
6+
## Table of content
7+
8+
- [Usage](#usage)
9+
- [Build & Publish](#build-publish)
10+
- [Information](#information)
11+
12+
## Usage
13+
14+
First, you have to install the package:
15+
16+
```bash
17+
npm install @aboutbits/pagination
18+
```
19+
20+
Second, you can call the calculate function by passing the following information:
21+
22+
- `page`: The current page
23+
- `size`: The amount of items shown per page
24+
- `total`: The amount of total items in the list/collection
25+
- `maxPages`: The maximum amount of pages that should be shown (default: 5)
26+
27+
In return, you receive an object with all relevant information:
28+
29+
```js
30+
import { calculatePagination } from '@aboutbits/pagination'
31+
32+
let pagination = calculatePagination(1, 5, 100)
33+
34+
console.log(pagination)
35+
```
36+
37+
This would return the following object:
38+
39+
```json
40+
{
41+
"previous": {
42+
"number": 1,
43+
"isDisabled": true
44+
},
45+
"next": {
46+
"number": 2,
47+
"isDisabled": false
48+
},
49+
"pages": [
50+
{
51+
"number": 1,
52+
"isCurrent": true
53+
},
54+
{
55+
"number": 2,
56+
"isCurrent": false
57+
},
58+
{
59+
"number": 3,
60+
"isCurrent": false
61+
},
62+
{
63+
"number": 4,
64+
"isCurrent": false
65+
},
66+
{
67+
"number": 5,
68+
"isCurrent": false
69+
}
70+
]
71+
}
72+
```
73+
74+
## Build & Publish
75+
76+
## Information
77+
78+
About Bits is a company based in South Tyrol, Italy. You can find more information about us on [our website](https://aboutbits.it).
79+
80+
### Support
81+
82+
For support, please contact [info@aboutbits.it](mailto:info@aboutbits.it).
83+
84+
### Credits
85+
86+
- [Alex Lanz](https://github.com/alexlanz)
87+
- [Martin Malfertheiner](https://github.com/mmalfertheiner)
88+
- [All Contributors](../../contributors)
89+
90+
### License
91+
92+
The MIT License (MIT). Please see the [license file](license.md) for more information.

src/__test__/pagination.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ it('should return only a few pages', () => {
1818
expect(pagination?.pages).toHaveLength(3)
1919

2020
expect(pagination?.pages[0].number).toBe(1)
21-
expect(pagination?.pages[0].isCurrentPage).toBeFalsy()
21+
expect(pagination?.pages[0].isCurrent).toBeFalsy()
2222
expect(pagination?.pages[1].number).toBe(2)
23-
expect(pagination?.pages[1].isCurrentPage).toBeTruthy()
23+
expect(pagination?.pages[1].isCurrent).toBeTruthy()
2424
expect(pagination?.pages[2].number).toBe(3)
25-
expect(pagination?.pages[2].isCurrentPage).toBeFalsy()
25+
expect(pagination?.pages[2].isCurrent).toBeFalsy()
2626
})
2727
it('should return the maximum number of pages', () => {
2828
const page = 5
@@ -35,15 +35,15 @@ it('should return the maximum number of pages', () => {
3535
expect(pagination?.pages).toHaveLength(5)
3636

3737
expect(pagination?.pages[0].number).toBe(3)
38-
expect(pagination?.pages[0].isCurrentPage).toBeFalsy()
38+
expect(pagination?.pages[0].isCurrent).toBeFalsy()
3939
expect(pagination?.pages[1].number).toBe(4)
40-
expect(pagination?.pages[1].isCurrentPage).toBeFalsy()
40+
expect(pagination?.pages[1].isCurrent).toBeFalsy()
4141
expect(pagination?.pages[2].number).toBe(5)
42-
expect(pagination?.pages[2].isCurrentPage).toBeTruthy()
42+
expect(pagination?.pages[2].isCurrent).toBeTruthy()
4343
expect(pagination?.pages[3].number).toBe(6)
44-
expect(pagination?.pages[3].isCurrentPage).toBeFalsy()
44+
expect(pagination?.pages[3].isCurrent).toBeFalsy()
4545
expect(pagination?.pages[4].number).toBe(7)
46-
expect(pagination?.pages[4].isCurrentPage).toBeFalsy()
46+
expect(pagination?.pages[4].isCurrent).toBeFalsy()
4747
})
4848
it('should disable the previous link', () => {
4949
const page = 1
@@ -59,8 +59,8 @@ it('should disable the previous link', () => {
5959
expect(pagination?.next.number).toBe(2)
6060
expect(pagination?.next.isDisabled).toBeFalsy()
6161

62-
expect(pagination?.pages[0].isCurrentPage).toBeTruthy()
63-
expect(pagination?.pages[1].isCurrentPage).toBeFalsy()
62+
expect(pagination?.pages[0].isCurrent).toBeTruthy()
63+
expect(pagination?.pages[1].isCurrent).toBeFalsy()
6464
})
6565
it('should disable the next link', () => {
6666
const page = 2
@@ -76,6 +76,6 @@ it('should disable the next link', () => {
7676
expect(pagination?.next.number).toBe(2)
7777
expect(pagination?.next.isDisabled).toBeTruthy()
7878

79-
expect(pagination?.pages[0].isCurrentPage).toBeFalsy()
80-
expect(pagination?.pages[1].isCurrentPage).toBeTruthy()
79+
expect(pagination?.pages[0].isCurrent).toBeFalsy()
80+
expect(pagination?.pages[1].isCurrent).toBeTruthy()
8181
})

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const calculatePagination = (
5656
}
5757
pages: {
5858
number: number
59-
isCurrentPage: boolean
59+
isCurrent: boolean
6060
}[]
6161
} | null => {
6262
if (total <= size) {
@@ -80,7 +80,7 @@ const calculatePagination = (
8080
(visiblePage) => {
8181
return {
8282
number: visiblePage,
83-
isCurrentPage: visiblePage === page,
83+
isCurrent: visiblePage === page,
8484
}
8585
}
8686
),

0 commit comments

Comments
 (0)