UNPKG

get-iterator

Version:

Get the default iterator or async iterator for an iterable or async iterable

15 lines 499 B
export function getIterator(obj) { if (obj != null) { if (typeof obj[Symbol.iterator] === 'function') { return obj[Symbol.iterator](); } if (typeof obj[Symbol.asyncIterator] === 'function') { return obj[Symbol.asyncIterator](); } if (typeof obj.next === 'function') { return obj; // probably an iterator } } throw new Error('argument is not an iterator or iterable'); } //# sourceMappingURL=index.js.map