An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3.
The npm package "es-iterator-helpers" is a robust solution designed to enhance the functionality of iterators in JavaScript. This package serves as a shim, polyfill, or replacement that is fully compliant with the ESnext specification, ensuring that it aligns perfectly with the latest JavaScript standards. Impressive for its backward compatibility, it supports environments as old as ES3, making it an ideal choice for projects that need to maintain legacy system compatibility while also leveraging modern JavaScript features. The "es-iterator-helpers" package simplifies the process of working with iterators, providing developers with a suite of powerful tools to handle iterable objects more efficiently and effectively.
To start using "es-iterator-helpers" in your project, simply run the command `npm install es-iterator-helpers`. This command integrates the package into your node environment, allowing you to immediately benefit from its extensive range of iterator utilities. Once installed, developers can utilize methods that streamline complex operations such as mapping, reducing, filtering, and more directly on iterators. This not only enhances code readability but also significantly improves performance by reducing the need for intermediate arrays. The "es-iterator-helpers" package is also well-supported with regular updates and a strong backing on GitHub, ensuring it remains reliable and up-to-date with the latest developments in JavaScript.
The "es-iterator-helpers" npm package is not only a practical addition to any JavaScript project but also a testament to the evolving capabilities of JavaScript development. Its compliance with the ESnext spec and support down to ES3 showcases its versatility and broad applicability across different project requirements and environments. For developers looking to optimize their code and streamline their development process with efficient iterator handling, "es-iterator-helpers" offers a proven, high-quality solution.
Core dependencies of this npm package and its dev dependencies.
call-bind, define-properties, es-abstract, es-errors, es-set-tostringtag, function-bind, get-intrinsic, globalthis, has-property-descriptors, has-proto, has-symbols, internal-slot, iterator.prototype, safe-array-concat, @es-shims/api, @ljharb/eslint-config, aud, auto-changelog, es-value-fixtures, eslint, eslint-plugin-import, evalmd, for-each, functions-have-names, has-strict-mode, has-tostringtag, in-publish, iterate-iterator, make-generator-function, mock-property, npmignore, nyc, object-inspect, safe-publish-latest, tape
A README file for the es-iterator-helpers code repository. View Code
An ESnext spec-compliant sync iterator helpers shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API “multi” interface. It works in an ES3-supported environment and complies with the spec.
Because the Iterator.prototype
methods depend on a receiver (the this
value), the main export in each subdirectory takes the iterator to operate on as the first argument.
The main export of the package itself is simply an array of the available directory names. It’s sole intended use is for build tooling and testing.
Iterator
constructorIterator.prototype
Iterator.from
Iterator.prototype.constructor
Iterator.prototype.drop
Iterator.prototype.every
Iterator.prototype.filter
Iterator.prototype.find
Iterator.prototype.flatMap
Iterator.prototype.forEach
Iterator.prototype.map
Iterator.prototype.reduce
Iterator.prototype.some
Iterator.prototype.take
Iterator.prototype.toArray
npm install --save es-iterator-helpers
const map = require('es-iterator-helpers/Iterator.prototype.map');
const toArray = require('es-iterator-helpers/Iterator.prototype.toArray');
const assert = require('assert');
const iterator = [1, 2, 3].values();
const mapped = map(iterator, (x) => x + 10);
assert.deepEqual(
mapped.next(),
{
done: false,
value: 11,
}
);
assert.deepEqual(
toArray(mapped),
[12, 13]
);
require('./auto'); // shim all of the methods
require('./Iterator.prototype.map/auto'); // shim the “map” method
Simply clone the repo, npm install
, and run npm test