Coder Social home page Coder Social logo

es-shims / iterator-helpers Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 1.0 221 KB

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

Home Page: https://tc39.es/proposal-iterator-helpers/

License: MIT License

JavaScript 100.00%
asynciterator drop ecmascript es-shims every filter find flatmap foreach from

iterator-helpers's Introduction

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 spec.

Because the Iterator.prototype methods depend on a receiver (the this value), the main export in each subdirectory takes the string 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

Getting started

npm install --save es-iterator-helpers

Usage/Examples

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

Tests

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

iterator-helpers's People

Contributors

ljharb avatar terrablue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

mb21

iterator-helpers's Issues

TypeError: `[[GeneratorState]]` is not present on `O`

Minimal example:

Detected this in [email protected]

// minimal-example.js
const map = require('es-iterator-helpers/Iterator.prototype.map');

function* myGenerator() {
  yield 1;
  yield 2;
  yield 3;
}

const mapped = map(myGenerator(), (x) => x ** 2);
console.log(mapped);

This triggers this error:

TypeError: `[[GeneratorState]]` is not present on `O`
    at Object.assert (redacted/node_modules/es-iterator-helpers/node_modules/internal-slot/index.js:19:10)
    at GeneratorStart (redacted/node_modules/es-iterator-helpers/aos/GeneratorStart.js:14:7)
    at CreateIteratorFromClosure (redacted/node_modules/es-iterator-helpers/aos/CreateIteratorFromClosure.js:45:2)
    at myGenerator.map (redacted/node_modules/es-iterator-helpers/Iterator.prototype.map/implementation.js:76:15)
    at Object.<anonymous> (redacted/minimal-example.js:9:16)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

es-iterator-helpers tried to access call-bind

This error shows up in the context of eslint-config-next with Yarn PnP:

- info Linting and checking validity of types .- error ESLint: Failed to load plugin 'react' declared in '.eslintrc.json » eslint-config-next/core-web-vitals » redacted/.yarn/__virtual__/eslint-config-next-virtual-3dd005a3fc/0/cache/eslint-config-next-npm-13.4.16-745205b385-c4b6849c4b.zip/node_modules/eslint-config-next/index.js': es-iterator-helpers tried to access call-bind, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Required package: call-bind Required by: es-iterator-helpers@npm:1.0.12 (via redacted/.yarn/cache/es-iterator-helpers-npm-1.0.12-35df79bd02-df1800a64b.zip/node_modules/es-iterator-helpers/Iterator.from/) Require stack: - redacted/.yarn/cache/es-iterator-helpers-npm-1.0.12-35df79bd02-df1800a64b.zip/node_modules/es-iterator-helpers/Iterator.from/index.js - redacted/.yarn/__virtual__/eslint-plugin-react-virtual-df620cb600/0/cache/eslint-plugin-react-npm-7.33.2-08f77ebc15-b4c3d76390.zip/node_modules/eslint-plugin-react/lib/util/Components.js - redacted/.yarn/__virtual__/eslint-plugin-react-virtual-df620cb600/0/cache/eslint-plugin-react-npm-7.33.2-08f77ebc15-b4c3d76390.zip/node_modules/eslint-plugin-react/lib/rules/boolean-prop-naming.js - redacted/.yarn/__virtual__/eslint-plugin-react-virtual-df620cb600/0/cache/eslint-plugin-react-npm-7.33.2-08f77ebc15-b4c3d76390.zip/node_modules/eslint-plugin-react/lib/rules/index.js - redacted/.yarn/__virtual__/eslint-plugin-react-virtual-df620cb600/0/cache/eslint-plugin-react-npm-7.33.2-08f77ebc15-b4c3d76390.zip/node_modules/eslint-plugin-react/configs/all.js - redacted/.yarn/__virtual__/eslint-plugin-react-virtual-df620cb600/0/cache/eslint-plugin-react-npm-7.33.2-08f77ebc15-b4c3d76390.zip/node_modules/eslint-plugin-react/index.js - redacted/.yarn/cache/@eslint-eslintrc-npm-2.1.2-feb0771c9f-bc742a1e3b.zip/node_modules/@eslint/eslintrc/dist/eslintrc.cjs Referenced from: redacted/.yarn/__virtual__/eslint-config-next-virtual-3dd005a3fc/0/cache/eslint-config-next-npm-13.4.16-745205b385-c4b6849c4b.zip/node_modules/eslint-config-next/index.js

Looks like there's a missing dependency on call-bind.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • [Deps] Update Update eslint to v8.57.0
  • [Deps] Update Update eslint to v9
  • [Deps] Update Update nyc to v15
  • 🔐 Create all pending approval PRs at once 🔐

Detected dependencies

github-actions
.github/workflows/node-aught.yml
.github/workflows/node-pretest.yml
.github/workflows/node-tens.yml
.github/workflows/rebase.yml
.github/workflows/require-allow-edits.yml
npm
package.json
  • call-bind ^1.0.7
  • define-properties ^1.2.1
  • es-abstract ^1.23.3
  • es-errors ^1.3.0
  • es-set-tostringtag ^2.0.3
  • function-bind ^1.1.2
  • get-intrinsic ^1.2.4
  • globalthis ^1.0.4
  • has-property-descriptors ^1.0.2
  • has-proto ^1.0.3
  • has-symbols ^1.0.3
  • internal-slot ^1.0.7
  • iterator.prototype ^1.1.2
  • safe-array-concat ^1.1.2
  • @es-shims/api ^2.5.0
  • @ljharb/eslint-config ^21.1.0
  • aud ^2.0.4
  • auto-changelog ^2.4.0
  • es-value-fixtures ^1.4.2
  • eslint =8.8.0
  • eslint-plugin-import ^2.29.1
  • evalmd ^0.0.19
  • for-each ^0.3.3
  • functions-have-names ^1.2.3
  • has-strict-mode ^1.0.1
  • has-tostringtag ^1.0.2
  • in-publish ^2.0.1
  • iterate-iterator ^1.0.2
  • make-generator-function ^2.0.0
  • mock-property ^1.0.3
  • npmignore ^0.3.1
  • nyc ^10.3.2
  • object-inspect ^1.13.1
  • safe-publish-latest ^2.0.0
  • tape ^5.7.5
  • node >= 0.4

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.