npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lopatnov/make-iterable

v3.1.0

Published

A TypeScript library that converts objects, functions, and their prototypes into Array-like iterable entities. Supports ES Modules, CommonJS, and UMD.

Readme

@lopatnov/make-iterable

A TypeScript library that converts objects, functions, and their prototypes into Array-like iterable entities. Apply it to a class prototype and every instance becomes iterable automatically.

npm downloads npm version License GitHub issues GitHub stars


Table of Contents


Installation

npm install @lopatnov/make-iterable

Browser (CDN):

<script src="//lopatnov.github.io/make-iterable/dist/make-iterable.umd.min.js"></script>

Usage

ES Modules

import makeIterable from "@lopatnov/make-iterable";

CommonJS

const makeIterable = require("@lopatnov/make-iterable");

Browser / UMD

<script src="make-iterable.umd.min.js"></script>
<script>
  // available as window.makeIterable
  var x = makeIterable({});
</script>

API

function makeIterable<T>(value: T): T & Array<any>;

Converts value to an Array-like iterable object in place and returns it. The original object reference is preserved — value === makeIterable(value).

The function attaches all Array.prototype methods (push, pop, splice, slice, indexOf, map, filter, forEach, etc.) and implements Symbol.iterator, enabling for...of loops and the spread operator.

Throws Error when value is undefined, null, a boolean, a number, or a string.


Examples

Make an Object Iterable and Array-Like

const x = { hello: "world" };
const iterableX = makeIterable(x);

iterableX.push(10); // [10]
iterableX.push(20); // [10, 20]
iterableX.push(30); // [10, 20, 30]
iterableX.push(40); // [10, 20, 30, 40]
iterableX.pop(); // [10, 20, 30]

for (const index in x) {
  console.log(`Index [${index}] = ${x[index]}`);
  // "Index [0] = 10"
  // "Index [1] = 20"
  // "Index [2] = 30"
  // "Index [hello] = world"
}

for (const value of x) {
  console.log(value); // 10, 20, 30
}

console.log(x === iterableX); // true
console.log(iterableX.indexOf(30)); // 2
console.log([...iterableX]); // [10, 20, 30]
console.log(iterableX.hello); // "world"

Make a Class Iterable via Prototype

class Simple {
  constructor(public message: string) {}
}

makeIterable(Simple.prototype);

const z = new Simple("Length is not enumerable now") as Simple & any[];
z.push([1, 2], [3, 4], [5, 6]);

for (const index in z) {
  console.log(`z[${index}]=${z[index]}`);
  // "z[0]=1,2"
  // "z[1]=3,4"
  // "z[2]=5,6"
  // "z[message]=Length is not enumerable now"
}

Make a Function Iterable

const fn = function () {};
const iterableFn = makeIterable(fn);

iterableFn.push(1, 2, 3, 4, 5);
console.log(iterableFn.indexOf(3)); // 2
console.log([...iterableFn]); // [1, 2, 3, 4, 5]

Demo


Contributing

Contributions are welcome! Please read CONTRIBUTING.md before opening a pull request.


Built With


License

Apache-2.0 © 2019–2026 Oleksandr Lopatnov · LinkedIn