Get an iterator for any JS language value. Works robustly across all environments, all versions.
In modern engines,
value[Symbol.iterator]() is sufficient to produce an iterator (an object with a
.next method) for that object. However, older engines:
- may lack
- may have
Symbol.iteratorbut not implement it on everything it should, like arguments objects
- may have
Set, but a non-standard name for the iterator-producing method (
- may be old versions of Firefox that produce values until they throw a StopIteration exception, rather than having iteration result objects
- may be polyfilled/shimmed/shammed, with
This library attempts to provide an abstraction over all that complexity!
In node v13+,
exports is used to provide a lean implementation that lacks all the complexity described above, in combination with the
browser field so that bundlers will pick up the proper implementation.
Targeting browsers with Symbol support
If you are targeting browsers that definitely all have Symbol support, then you can configure your bundler to replace
require('has-symbols')() with a literal
true, which should allow dead code elimination to reduce the size of the bundled code.
var getIterator = ;var assert = ;var iterator = ;assert;var iterator = ;assert;var iterator = ;assert;var iterator = ;assert;
Simply clone the repo,
npm install, and run