Skip to content

Commit f9e965e

Browse files
committed
2.0.0 release
1 parent 259ce7e commit f9e965e

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

README.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# hapi-pagination
22

3-
[![Greenkeeper badge](https://badges.greenkeeper.io/fknop/hapi-pagination.svg)](https://greenkeeper.io/)
4-
53
[![NPM Version](https://img.shields.io/npm/v/hapi-pagination.svg)](https://npmjs.org/package/hapi-pagination)
64
[![Build Status](https://travis-ci.org/fknop/hapi-pagination.svg)](https://travis-ci.org/fknop/hapi-pagination)
75
[![Coverage Status](https://coveralls.io/repos/fknop/hapi-pagination/badge.svg?branch=master&service=github)](https://coveralls.io/github/fknop/hapi-pagination?branch=master)
@@ -15,6 +13,10 @@ Hapi plugin to handle 'custom' resources pagination in json only.
1513
npm install hapi-pagination --save
1614
```
1715

16+
## Version 2.0.0
17+
18+
Version 2.0.0 is intended for use with Hapi 1.17.x and above, do not use this version for version below 1.17.x of hapi.
19+
1820
## Contribute
1921

2022
Post an issue if you encounter a bug or an error in the documentation.
@@ -139,15 +141,16 @@ config: {
139141
}
140142
```
141143

142-
#### reply.paginate(Array|Object, [totalCount], [options = {}])
144+
#### h.paginate(Array|Object, [totalCount], [options = {}])
143145

144146
The method is an helper method. This is a shortcut for:
145147

146148
```javascript
147-
reply({results: results, totalCount: totalCount});
149+
h.response({results: results, totalCount: totalCount});
148150
```
149151

150152
You can change names of fields (`results`, `totalCount`) using reply options.
153+
151154
```
152155
reply: {
153156
results: {
@@ -164,7 +167,7 @@ You can also reply the array and set the totalCount by adding the totalCount
164167

165168
```
166169
request.totalCount = 10;
167-
reply(results);
170+
h.response(results);
168171
```
169172

170173
The `paginate` method also offers a way to add custom properties to your response. You just have to
@@ -173,7 +176,7 @@ pass an object as first parameter and pass a `options.key` parameter which is th
173176
For example:
174177

175178
```
176-
return reply.paginate({ results: [], otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
179+
return h.paginate({ results: [], otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });
177180
```
178181

179182
The response will also contains `otherKey` and `otherKey2`. Nested keys for the paginated results are not allowed.
@@ -185,7 +188,7 @@ Please note that if you pass metadata in headers the custom properties don't wor
185188
##### WARNING: If the results is not an array, the program will throw an implementation error.
186189

187190
If totalCount is not exposed through the request object
188-
or the reply.paginate method, the following attributes will be
191+
or the h.paginate method, the following attributes will be
189192
set to null if they are active.
190193
* `last`
191194
* `pageCount`
@@ -296,22 +299,19 @@ const options = {
296299
```javascript
297300
const Hapi = require('hapi');
298301

299-
let server = new Hapi.Server();
302+
const server = new Hapi.Server();
300303

301304
// Add your connection
302305

303-
server.register(require('hapi-pagination'), (err) => {
304-
if (err)
305-
throw err;
306-
});
306+
await server.register(require('hapi-pagination'))
307307
```
308308

309309
### Example with options
310310

311311
```javascript
312312
const Hapi = require('hapi');
313313

314-
let server = new Hapi.Server();
314+
const server = new Hapi.Server();
315315

316316
// Add your connection
317317

@@ -350,11 +350,7 @@ const options = {
350350
}
351351
};
352352

353-
server.register({register: require('hapi-pagination'), options: options}, (err)
354-
=> {
355-
if (err)
356-
throw err;
357-
});
353+
await server.register({plugin: require('hapi-pagination'), options: options})
358354
```
359355
### Disable globally and activate pagination on specific routes
360356

@@ -363,7 +359,7 @@ Global configuration:
363359
```javascript
364360
const Hapi = require('hapi');
365361

366-
let server = new Hapi.Server();
362+
const server = new Hapi.Server();
367363

368364
// Add your connection
369365

@@ -374,11 +370,7 @@ const options = {
374370
}
375371
};
376372

377-
server.register({register: require('hapi-pagination'), options: options}, (err)
378-
=> {
379-
if (err)
380-
throw err;
381-
});
373+
await server.register({plugin: require('hapi-pagination'), options: options})
382374
```
383375
Activate on route level:
384376

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hapi-pagination",
3-
"version": "1.22.0",
3+
"version": "2.0.0",
44
"description": "A hapi plugin to paginate resources",
55
"main": "lib/index.js",
66
"scripts": {
@@ -29,4 +29,4 @@
2929
"coveralls": "^3.0.0",
3030
"lab": "^15.1.2"
3131
}
32-
}
32+
}

0 commit comments

Comments
 (0)