Skip to content

Commit 8084afd

Browse files
committed
feat: .paginate(options, mapFn)
1 parent 34011c7 commit 8084afd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

plugins/pagination/paginate.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@ module.exports = paginate
22

33
const iterator = require('./iterator')
44

5-
function paginate (octokit, route, options) {
5+
function paginate (octokit, route, options, mapFn) {
6+
if (typeof options === 'function') {
7+
mapFn = options
8+
options = undefined
9+
}
610
options = octokit.request.endpoint.merge(route, options)
7-
return gather([], iterator(octokit, options)[Symbol.asyncIterator]())
11+
return gather([], iterator(octokit, options)[Symbol.asyncIterator](), mapFn)
812
}
913

10-
function gather (results, iterator) {
14+
function gather (results, iterator, mapFn) {
1115
return iterator.next()
1216
.then(result => {
1317
if (result.done) {
1418
return results
1519
}
1620

17-
results.push.apply(results, result.value.data)
18-
return gather(results, iterator)
21+
results.push.apply(results, mapFn ? mapFn(result.value) : result.value.data)
22+
return gather(results, iterator, mapFn)
1923
})
2024
}

0 commit comments

Comments
 (0)