Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

es-iterator-helpers

es-shims45.6mMIT1.2.1

An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3.

javascript, ecmascript, polyfill, shim, es-shims, es-shim API, Iterator, helpers, from, map, filter, take, drop, flatMap, reduce, toArray, forEach, some, every, find

readme

es-iterator-helpers Version Badge

github actions coverage License Downloads

npm badge

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 iterator helpers spec and the iterator sequencing 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.

Supported things

Environments where this is needed

  • node v22, Chrome >= v122: has a bug
  • node < v22, Chrome < v122, Safari <= v17.1, Firefox <= v125: not implemented
  • all environments lack Iterator.concat, Iterator.zip, Iterator.zipKeyed

Getting started

npm install --save es-iterator-helpers

Usage/Examples

Using explicit imports:

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

Shim using require:

require('es-iterator-helpers/auto'); // shim all of the methods

require('es-iterator-helpers/Iterator.prototype.map/auto'); // shim the “map” method

Shim using import syntax:

import 'es-iterator-helpers/auto'; // shim all of the methods

import 'es-iterator-helpers/Iterator.prototype.map/auto'; // shim the “map” method

Tests

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.2.1 - 2024-12-20

Commits

  • [Tests] Iterator.concat: add most of the tests from https://github.com/tc39/test262/pull/4326 2e340da
  • [Fix] Iterator.concat: rewrite implementation to match updated spec text 1a70fd3
  • [Fix] IteratorZip AO: allow an empty list of iterators 265e566
  • [actions] split out node 10-20, and 20+ 3cc9db0
  • [Fix] IteratorHelperPrototype: in pre-proto envs, use same .return impl da02ab6
  • [Deps] update call-bind, es-abstract, get-intrinsic, gopd, has-proto, internal-slot, iterator.prototype, safe-array-concat e9eefab
  • [Tests] Iterator.zip: nullish non-function Symbol.iterator does not throw c6b0705
  • [Refactor] use call-bound directly 92afc5a
  • [Deps] update gopd, has-proto, has-symbols 7f8a1c0
  • [readme] add missing info for Iterator.zip, Iterator.zipKeyed dd80b2f
  • [Dev Deps] update @es-shims/api 1e9857c
  • [Deps] update es-abstract c8157da
  • [Deps] update es-abstract 256de0e
  • [Dev Deps] update object-inspect 2f8544b

v1.2.0 - 2024-11-04

Commits

  • [New] add Iterator.zip, Iterator.zipKeyed d11073f
  • [Fix] concat: add missing slot for .return; convert singular slot to plural slot cc4b586
  • [Dev Deps] update @es-shims/api dd14f1b

v1.1.0 - 2024-10-09

Commits

  • [New] add Iterator.concat 1c07c21
  • [readme] add ESM and CJS examples ae0b60c
  • [Dev Deps] update @es-shims/api, auto-changelog, es-value-fixtures, eslint-plugin-import, tape bd34766
  • [Dev Deps] update @ljharb/eslint-config, mock-property, object-inspect, tape 2016080
  • [readme] fix copy-paste errors 799255c
  • [Tests] replace aud with npm audit 4c48a77
  • [Deps] update globalthis 14d9e97
  • [Dev Deps] update @es-shims/api 15d84bb
  • [Dev Deps] add missing peer dep 34559b9

v1.0.19 - 2024-04-24

Commits

  • [patch] remove unused AOs 698cef7
  • [Fix] drop, filter, flatMap, map: rpatch a v8 bug when polyfilling 3670395
  • [Deps] update es-abstract d2b47a5

v1.0.18 - 2024-03-15

Commits

  • [Deps] update es-abstract 6b45f15
  • [Deps] update es-set-tostringtag, has-proto, safe-array-concat 6350106
  • [Dev Deps] update tape 5509b40
  • [Deps] remove an unused dep 78e34a5

v1.0.17 - 2024-02-13

Fixed

  • [Fix] avoid use of internal assertRecord helper from es-abstract #5

Commits

  • [Deps] update call-bind, es-abstract, has-property-descriptors e563ee7

v1.0.16 - 2024-02-09

Commits

  • [Refactor] use IteratorStepValue aa62d72
  • [Refactor] use es-errors instead of get-intrinsic where possible 05a25ae
  • [Deps] update call-bind, es-abstract, es-set-tostringtag, function-bind, get-intrinsic, has-property-descriptors, internal-slot, safe-array-concat 6aeee43
  • [Dev Deps] update aud, eslint-plugin-import, mock-property, npmignore, object-inspect, tape 0a21fdb
  • [Deps] update call-bind, es-errors, get-intrinsic, internal-slot 5b10625
  • [meta] add missing engines.node 1534039
  • [Deps] update get-intrinsic 37da5f2
  • [Dev Deps] update has-tostringtag a7cac51

v1.0.15 - 2023-09-13

Commits

  • [New] add Iterator.prototype shim c4a6203
  • [Tests] add passing tests for native generators 57bae8c
  • [Deps] update define-properties, iterator.prototype, safe-array-concat 56ca087

v1.0.14 - 2023-08-26

Commits

  • [Deps] update es-abstract 477b123
  • [Dev Deps] update aud, eslint-plugin-import, tape e4ea414

v1.0.13 - 2023-08-16

Fixed

  • [Deps] add missing deps; add eslint-plugin-import #3

v1.0.12 - 2023-07-14

Commits

v1.0.11 - 2023-05-22

Commits

  • [Fix] iterator helpers are not a constructor 8a7f999

v1.0.10 - 2023-05-18

Commits

  • [patch] remove IsCallable check on NextMethod, deferring errors to callsite bbb7efa
  • [patch] change Symbol.iterator fallback from callable check to nullish check ec3e255
  • [Tests] add test cases 5117c47
  • [Dev Deps] update @es-shims/api 9fa13a0
  • [Dev Deps] update @es-shims/api b74b0ac

v1.0.9 - 2023-05-02

Commits

  • [Refactor] use 2022 AO instead of 2015 AO 75ee5c4

v1.0.8 - 2023-05-02

Commits

  • [Fix] flatMap: close the inner iterator when applicable 4dc94e0

v1.0.7 - 2023-05-01

Commits

  • [Fix] flatMap: properly handle yielded iterables 3a78767
  • [Fix] flatMap: only increment the count when iterating the outer iterator 955d0b0

v1.0.6 - 2023-04-20

Commits

  • [Refactor] GetIteratorFlattenable: remove hint 781fc7c
  • [Refactor] GetIteratorFlattenable: use GetIteratorDirect 026118b
  • [Refactor] use safe-array-concat 1d985a4

v1.0.5 - 2023-03-22

Commits

  • [Tests] add passing tests for 4240029 c2082fe
  • [Fix] properly allow subclasses of Iterator to be constructed 5cebe2a

v1.0.4 - 2023-03-21

Commits

  • [Fix] validate arguments first 4240029
  • [Fix] close underlying iterator when helper is closed f5372c7
  • [Tests] Iterator: remove an unnecessary call-bind 7d0ba59

v1.0.3 - 2023-03-17

Commits

  • [Fix] drop/filter/flatMap/map/take: properly IfAbruptCloseIterator ff643a0
  • [Refactor] use NormalCompletion/ThrowCompletion instead of thunks 68fd937
  • [Fix] filter: IteratorClose needs to rethrow the error 200474f
  • [Fix] filter: properly increment the counter 14aa2d8
  • [Fix] Iterator can not be newed or invoked directly 6fbd68e
  • [Fix] Iterator.prototype should be non-writable 1080288
  • [Deps] update es-abstract b7913da
  • [Dev Deps] update @es-shims/api 0071bed

v1.0.2 - 2023-02-09

Commits

  • [Refactor] inline 2023 impls of Iterator AOs until es-abstract is published with them b9c80c5
  • [Fix] ensure calling .return does not invoke the next iteration 9e28ed5
  • [Fix] map: pass the proper index argument to the mapper 125e3ca
  • [Deps] update internal-slot 43351b6

v1.0.1 - 2023-02-07

Commits

  • [Fix] Iterator: throw when Iterator() is called without new a6fc7e7

v1.0.0 - 2023-02-05

Commits