nl_tokens: We allow four forms of the onItem callback ( the middle two being equivalent )
pl_tokens: function getItemCallback ( args ) { if ( args . length === 0 ) { return undefined ; } var onItem = args [ 0 ] ; if ( typeof onItem !== 'function' ) { throw Error ( 'The first argument to autoPagingEach, if present, must be a callback function; receieved ' + typeof onItem ) ; } // 4. `.autoPagingEach((item, next) => { doSomething(item); next(false); });` if ( onItem . length === 2 ) { return onItem ; } if ( onItem . length > 2 ) { throw Error ( 'The `onItem` callback function passed to autoPagingEach must accept at most two arguments; got ' + onItem ) ; } // This magically handles all three of these usecases (the latter two being functionally identical): // 1. `.autoPagingEach((item) => { doSomething(item); return false; });` // 2. `.autoPagingEach(async (item) => { await doSomething(item); return false; });` // 3. `.autoPagingEach((item) => doSomething(item).then(() => false));` return function _onItem ( <mask> , next ) { var shouldContinue = onItem ( item ) ; next ( shouldContinue ) ; } ; }