{"id":11118,"library":"iterall","title":"Iterall: JavaScript Iterables for All Environments","description":"Iterall is a minimalist, zero-dependency utility library designed to enable the use of JavaScript Iterables and AsyncIterables across all JavaScript environments, including older versions of Internet Explorer. It provides crucial helpers for libraries that wish to accept various iterable inputs (like Arrays, Maps, Sets, NodeLists, TypedArrays, or custom data structures) instead of being limited to only Arrays. The current stable version is 1.3.0, and the project maintains a steady release cadence with improvements to TypeScript definitions and async iterator support. Its key differentiators include its tiny footprint (under 1KB gzipped), its 'library for libraries' approach, and its robust compatibility with both modern and legacy JavaScript runtimes through its intelligent fallback mechanism for `Symbol.iterator`.","status":"active","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/leebyron/iterall","tags":["javascript","es6","iterator","iterable","polyfill","for-of","typescript"],"install":[{"cmd":"npm install iterall","lang":"bash","label":"npm"},{"cmd":"yarn add iterall","lang":"bash","label":"yarn"},{"cmd":"pnpm add iterall","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM, use named imports. For CommonJS, use require. Since v1.2.0, `.mjs` files are published for better ESM compatibility and tree-shaking.","wrong":"const isCollection = require('iterall').isCollection;","symbol":"isCollection","correct":"import { isCollection } from 'iterall';"},{"note":"This utility allows iterating over any Iterable or Array-like structure, even in environments without native Symbol.iterator.","wrong":"const forEach = require('iterall').forEach;","symbol":"forEach","correct":"import { forEach } from 'iterall';"},{"note":"Introduced in v1.1.0, this function provides a universal way to iterate over AsyncIterables, returning a Promise. Ensure you are on v1.1.3 or higher for critical bug fixes.","wrong":"const forAwaitEach = require('iterall').forAwaitEach;","symbol":"forAwaitEach","correct":"import { forAwaitEach } from 'iterall';"}],"quickstart":{"code":"import { isCollection, forEach, forAwaitEach } from 'iterall';\n\n// Example 1: Handling various synchronous collections\nfunction processCollection(data) {\n  if (isCollection(data)) {\n    forEach(data, (item, index) => {\n      console.log(`Sync Item ${index}: ${item}`);\n    });\n    console.log('Finished synchronous iteration.');\n  } else {\n    console.log('Input is not a recognized collection.');\n  }\n}\n\nprocessCollection([1, 2, 3]);\nprocessCollection(new Set(['a', 'b']));\n\n// Example 2: Handling asynchronous iterables\nasync function* asyncGenerator() {\n  yield 'hello';\n  await new Promise(resolve => setTimeout(resolve, 100));\n  yield 'world';\n}\n\nasync function processAsyncIterable(asyncData) {\n  console.log('Starting asynchronous iteration...');\n  await forAwaitEach(asyncData, (item, index) => {\n    console.log(`Async Item ${index}: ${item}`);\n  });\n  console.log('Finished asynchronous iteration.');\n}\n\nprocessAsyncIterable(asyncGenerator());","lang":"typescript","description":"Demonstrates how to use `isCollection` to check for iterable/array-like structures and `forEach` for synchronous iteration, along with `forAwaitEach` for handling asynchronous iterables, all compatible across environments."},"warnings":[{"fix":"Assess your target environment compatibility. If only modern ES environments are targeted, native `for...of` loops and `Array.from` might suffice. Otherwise, `iterall` is beneficial for broader compatibility.","message":"Iterall's primary value is in providing polyfills and fallbacks for Iteration Protocols in older JavaScript environments (pre-ES2015 or limited browser support). If you are strictly targeting modern ES2015+ environments that fully support `Symbol.iterator`, you might be able to use native iteration directly without `iterall`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check your bundler configuration (e.g., `resolve.extensions` in Webpack) to ensure `.mjs` is included. For Node.js, ensure your `package.json` specifies `type: 'module'` or uses `.mjs` extensions for ESM files.","message":"For optimal tree-shaking and better ESM compatibility with bundlers like Rollup or Webpack, `iterall` has published `.mjs` files since `v1.2.0`. Ensure your build configuration is set up to resolve `.mjs` files correctly, especially in dual CommonJS/ESM setups.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"If using `forAwaitEach` for asynchronous iteration, ensure your project depends on `iterall` version `1.1.3` or newer to avoid memory leaks and unhandled promise rejections.","message":"Early versions of `forAwaitEach` (before v1.1.2) had a memory leak issue, and v1.1.2 introduced a fix for this. Subsequently, v1.1.3 fixed an issue where errors within `forAwaitEach` were not caught.","severity":"gotcha","affected_versions":">=1.1.0 <1.1.3"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use `iterall.forEach(myIterable, callback)` or `iterall.isIterable(myIterable)` to ensure compatibility across all environments, as `iterall` handles the fallback to `@@iterator`.","cause":"Attempting to iterate over a custom object or non-native iterable in an older JavaScript environment without leveraging `iterall`'s polyfill utilities, leading to the absence of the `Symbol.iterator` global.","error":"TypeError: 'Symbol.iterator' is not defined"},{"fix":"Change your import statements to CommonJS `require` syntax: `const { forEach } = require('iterall');` or configure your Node.js project or build pipeline to support ESM.","cause":"Using `import ... from 'iterall'` syntax in a Node.js environment configured for CommonJS (e.g., without `\"type\": \"module\"` in `package.json` or a transpiler like Babel).","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Verify `iterall` is correctly installed in `node_modules`. If using a bundler, ensure its configuration supports resolving `.mjs` files (e.g., `resolve.extensions` in Webpack should include `'.mjs'`).","cause":"A bundler (like Webpack) is failing to resolve the `iterall` package, potentially due to incorrect pathing or module resolution configuration, especially concerning its `.mjs` files.","error":"Module not found: Error: Can't resolve 'iterall'"}],"ecosystem":"npm"}