File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -2,19 +2,23 @@ module.exports = paginate
2
2
3
3
const iterator = require ( './iterator' )
4
4
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
+ }
6
10
options = octokit . request . endpoint . merge ( route , options )
7
- return gather ( [ ] , iterator ( octokit , options ) [ Symbol . asyncIterator ] ( ) )
11
+ return gather ( [ ] , iterator ( octokit , options ) [ Symbol . asyncIterator ] ( ) , mapFn )
8
12
}
9
13
10
- function gather ( results , iterator ) {
14
+ function gather ( results , iterator , mapFn ) {
11
15
return iterator . next ( )
12
16
. then ( result => {
13
17
if ( result . done ) {
14
18
return results
15
19
}
16
20
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 )
19
23
} )
20
24
}
You can’t perform that action at this time.
0 commit comments