response-iterator
Version:
Creates an async iterator for a variety of inputs in the browser and node. Supports fetch, node-fetch, and cross-fetch
15 lines (14 loc) • 411 B
JavaScript
const hasIterator = typeof Symbol !== 'undefined' && Symbol.asyncIterator;
/* c8 ignore start */ export default function readerIterator(reader) {
const iterator = {
next () {
return reader.read(undefined);
}
};
if (hasIterator) {
iterator[Symbol.asyncIterator] = function() {
return this;
};
}
return iterator;
} /* c8 ignore stop */