digitransit-ui/app/util/getIterator.js
2024-02-08 14:56:31 +02:00

14 lines
366 B
JavaScript

function isObject(it) {
return typeof it === 'object' ? it !== null : typeof it === 'function';
}
export default function iter(it) {
const iterFn = it[Symbol.iterator];
if (typeof iterFn !== 'function') {
throw TypeError(`${it} is not iterable!`);
}
if (!isObject(it)) {
throw TypeError(`${it} is not an object!`);
}
return iterFn.call(it);
}