es-get-iterator

WebJar for es-get-iterator

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

es-get-iterator
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

jar
Description

Description

es-get-iterator
WebJar for es-get-iterator
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/ljharb/es-get-iterator

Download es-get-iterator

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/es-get-iterator/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>es-get-iterator</artifactId>
    <version>1.1.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/es-get-iterator/
implementation 'org.webjars.npm:es-get-iterator:1.1.2'
// https://jarcasting.com/artifacts/org.webjars.npm/es-get-iterator/
implementation ("org.webjars.npm:es-get-iterator:1.1.2")
'org.webjars.npm:es-get-iterator:jar:1.1.2'
<dependency org="org.webjars.npm" name="es-get-iterator" rev="1.1.2">
  <artifact name="es-get-iterator" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='es-get-iterator', version='1.1.2')
)
libraryDependencies += "org.webjars.npm" % "es-get-iterator" % "1.1.2"
[org.webjars.npm/es-get-iterator "1.1.2"]

Dependencies

compile (8)

Group / Artifact Type Version
org.webjars.npm : is-map jar [2.0.2,3)
org.webjars.npm : get-intrinsic jar [1.1.0,2)
org.webjars.npm : isarray jar [2.0.5,3)
org.webjars.npm : is-set jar [2.0.2,3)
org.webjars.npm : call-bind jar [1.0.2,2)
org.webjars.npm : is-string jar [1.0.5,2)
org.webjars.npm : has-symbols jar [1.0.1,2)
org.webjars.npm : is-arguments jar [1.1.0,2)

Project Modules

There are no modules declared in this project.

es-get-iterator Version Badge

dependency status dev dependency status License Downloads

npm badge

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 Symbol support altogether
  • may have Symbol.iterator but not implement it on everything it should, like arguments objects
  • may have Map and Set, but a non-standard name for the iterator-producing method (.iterator or ['@@iterator'], eg)
  • 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 es6-shim or core-js or similar

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.

With @rollup/plugin-replace

// rollup.config.js

import replace from '@rollup/plugin-replace';

export default {
	...
	plugins: [
		replace({
			"require('has-symbols')()": 'true',
			delimiters: ['', '']
		})
	]
};

Example

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 }]
);

Tests

Simply clone the repo, npm install, and run npm test

Versions

Version
1.1.2
1.1.1
1.1.0