This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
TripSit_Suite/node_modules/iterate-iterator/index.js
2020-11-01 22:46:04 +00:00

29 lines
728 B
JavaScript

'use strict';
var $TypeError = TypeError;
// eslint-disable-next-line consistent-return
module.exports = function iterateIterator(iterator) {
if (!iterator || typeof iterator.next !== 'function') {
throw new $TypeError('iterator must be an object with a `next` method');
}
if (arguments.length > 1) {
var callback = arguments[1];
if (typeof callback !== 'function') {
throw new $TypeError('`callback`, if provided, must be a function');
}
}
var values = callback || [];
var result;
while ((result = iterator.next()) && !result.done) {
if (callback) {
callback(result.value); // eslint-disable-line callback-return
} else {
values.push(result.value);
}
}
if (!callback) {
return values;
}
};