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
22
33const 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}
You can’t perform that action at this time.
0 commit comments