Mohammad Asif cf937194cb Removed un-waned things 1. | 5 ay önce | |
---|---|---|
.. | ||
.github | 5 ay önce | |
test | 5 ay önce | |
.eslintrc | 5 ay önce | |
.nycrc | 5 ay önce | |
CHANGELOG.md | 5 ay önce | |
LICENSE | 5 ay önce | |
README.md | 5 ay önce | |
index.js | 5 ay önce | |
node.js | 5 ay önce | |
node.mjs | 5 ay önce | |
package.json | 5 ay önce |
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:
Symbol
support altogetherSymbol.iterator
but not implement it on everything it should, like arguments objectsMap
and Set
, but a non-standard name for the iterator-producing method (.iterator
or ['@@iterator']
, eg)es6-shim
or core-js
or similarThis 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.
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.
@rollup/plugin-replace
// rollup.config.js
import replace from '@rollup/plugin-replace';
export default {
...
plugins: [
replace({
"require('has-symbols')()": 'true',
delimiters: ['', '']
})
]
};
var getIterator = require('es-get-iterator');
var assert = require('assert');
var iterator = getIterator('a 💩');
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: 'a' }, { done: false, value: ' ' }, { done: false, value: '💩' }, { done: true, value: undefined }]
);
var iterator = getIterator([1, 2]);
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: 1 }, { done: false, value: 2 }, { done: true, value: undefined }]
);
var iterator = getIterator(new Set([1, 2]));
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: 1 }, { done: false, value: 2 }, { done: true, value: undefined }]
);
var iterator = getIterator(new Map([[1, 2], [3, 4]]));
assert.deepEqual(
[iterator.next(), iterator.next(), iterator.next()],
[{ done: false, value: [1, 2] }, { done: false, value: [3, 4] }, { done: true, value: undefined }]
);
Simply clone the repo, npm install
, and run npm test