gas-xtutils is GAS (Google Apps Script) xtetsuji's utility .
It has some useful classes powered by ES2015 syntax. You can use it on V8 runtime.
Advanced Google Services API (e.g. Tasks API) has paging system as following description.
- call
XXX.list()
and get first page objectfirst
, first page contents includefirst.items
array. - if
first.nextPageToken
property is exist, then callXXX.list({pageToken: first.nextPageToken})
and get second page objectsecond
, second page contents includesecond.items
array. - if
second.nextPageToken
property ...(ditto)...
In this situation, you can write easy iteration by PagesIterator.
const pages = new PagesIterator(
token => token ? XXX.list() : XXX.list({pageToken: token})
);
for ( const item of pages ) {
console.log(`- ${item.title}`);
}
PagesIterator constructor has the iterable protocol. You can use PagesIterator on following contexts.
Array.from(iterable)
...iterable
[a, b, c] = iterable