response-iterator
Advanced tools
Comparing version 0.1.0 to 0.1.1
function streamIterator(stream) { | ||
const iterator = stream[Symbol.asyncIterator](); | ||
return { | ||
next: function () { | ||
next() { | ||
return iterator.next(); | ||
}, | ||
[Symbol.asyncIterator]: function () { | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
} | ||
}; | ||
@@ -17,8 +19,10 @@ } | ||
return { | ||
next: function () { | ||
next() { | ||
return reader.read(); | ||
}, | ||
[Symbol.asyncIterator]: function () { | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
} | ||
}; | ||
@@ -30,3 +34,3 @@ } | ||
return { | ||
next: function () { | ||
next() { | ||
if (resolved) return Promise.resolve({ | ||
@@ -46,5 +50,7 @@ value: undefined, | ||
}, | ||
[Symbol.asyncIterator]: function () { | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
} | ||
}; | ||
@@ -51,0 +57,0 @@ } |
@@ -5,10 +5,6 @@ import { Response as NodeResponse } from "node-fetch"; | ||
} | ||
export interface IterableIterator<T> { | ||
next(): Promise<IteratorResult<T, boolean>>; | ||
[Symbol.asyncIterator](): Promise<IteratorResult<T, boolean>>; | ||
} | ||
/** | ||
* @param response A response. Supports fetch, node-fetch, and cross-fetch | ||
*/ | ||
export default function responseIterator<T>(response: Response | NodeResponse | CrossFetchResponse): IterableIterator<T>; | ||
export default function responseIterator<T>(response: Response | NodeResponse | CrossFetchResponse): AsyncIterableIterator<T>; | ||
export {}; |
{ | ||
"name": "response-iterator", | ||
"description": "Creates an async iterator for a variety of inputs in the browser and node. Supports fetch, node-fetch, and cross-fetch", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "email": "kmalakoff@gmail.com", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29621
225