![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Fun with Iterables
npm install iter-fun
import { getOrCreateIterator } from "iter-fun";
// if the object has an iterator, return it
// if not, create one from the object
const iter = getOrCreateIterator(obj);
import { isArray } from "iter-fun";
isArray([1, 2, 3]); // true
import { isIterator } from "iter-fun";
isIterator([1, 2, 3][Symbol.iterator]()); // true
import { hasNext } from "iter-fun";
hasNext({ next: () => {...} }); // true
import { hasIterator } from "iter-fun";
hasIterator({ "@@iterator": ... }); // true
import { hasSymbolIterator } from "iter-fun";
hasSymbolIterator(Array); // true
import { getIterator } from "iter-fun";
const iter = getIterator([1, 2]);
iter.next(); // { value: 1, done: false }
iter.next(); // { value: 2, done: false }
iter.next() // { done: true }
import { createIterator } from "iter-fun";
// obj must have a length property
// and index-addressable data like obj[123]
const iter = createIterator(obj);
import { addSymbolIterator } from "iter-fun";
const obj = { next: () => {...} };
addSymbolIterator(obj);
// modifies the object in-place adding a [Symbol.iterator] key
import { addSymbolIteratorFallback } from "iter-fun";
const obj = { next: () => {...} };
addSymbolIteratorFallback(obj);
// modifies the object in-place adding a "@@iterator" string key
// helpful if you are running in an old browser
import { wrapNextFunction } from "iter-fun";
const next = () => { ... };
const iter = wrapNextFunction(next);
// converts a next function into a fully functioning iterable
import { zip } from "iter-fun";
const zeros = [0, 0, 0, ...];
const twos = [2, 2, 2, ...];
const sixties = [60, 60, 60, ...];
const iters = [zeros, twos, sixties];
const zipped = zip(iters);
zipped.next();
// { done: false, value: [0, 2, 60] }
FAQs
Fun with Iterables
The npm package iter-fun receives a total of 3,865 weekly downloads. As such, iter-fun popularity was classified as popular.
We found that iter-fun demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.