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 🙏

© 2025 – Pkg Stats / Ryan Hefner

xiter

v1.1.0

Published

Extended iterables such as `Set`.

Readme

xiter - Extended iterables

Build Status Coverage Status npm version Downloads

Extensions of ES6 iterables such as Set.

Problem

Many iterables (such as Set, for instance) lack methods supporting common iterator operations (such as map, filter, every, etc.).

Array is the only iterable that currently provides all these methods. Consequently, in order to perform one of these operations on a non-Array iterable, one must convert the iterable into an Array, perform the operation, and convert it back to the original type of iterable.

For example, suppose you had the following Set and mapper function:

const original: Set<string> = ...;
function mapper(s: string): number { ... }

Ideally, you would be able to write:

const mapped = original.map(mapper);

...but in reality, you have to write:

const mapped = new Set(Array.from(original).map(mapper));

Notice how much more readable the former is. If your codebase frequently performs these iterator operations, readability improvements like these will quickly add up.

Unfortunately, the former currently throws an error, because the native Set does not provide a map method.

Solution

xiter provides thorougly tested and documented extensions of native iterables that provide these methods.

These extensions are fully backwards-compatible, allowing you to confidently replace any native iterables with their extended counterparts without fear of breaking your codebase.

Usage

npm install --save xiter
import { XSet } from "xiter";

const a = new XSet(["x", "y", "z"]);
const b = new XSet([8, "z", false]);

function printSet(s: Set<any>): void {
  console.log(Array.from(s));
}

// XSets behave like native Sets...

console.log(a instanceof Set); // true
console.log(a.has("z"), a.has("w")); // true, false;
console.log(a.delete("z"), a.delete("z")); // true, false
a.add("z");
console.log(a.size); // 3

// ...but have additional methods you would expect all iterables to have (e.g., map)...

printSet(a.map(s => s.toUpperCase())); // ["X", "Y", "Z"]
printSet(b.filter(x => "number" === typeof x)); // [8]
console.log(b.find(x => "number" === typeof x); // 8
console.log(b.some(x => "number" === typeof x); // true
console.log(b.every(x => "number" === typeof x); // false

// See API Docs for the rest of the methods.

API Docs

Docs can be found here.

("Bonus") class-specific methods

As a bonus, some extensions provide additional class-specific methods for your convenience. For example, XSet provides methods implementing common set operations, such as union and isSubsetOf.

These methods, despite being completely unrelated to solving the original problem of providing iterator operations, were included as a part of this library because the author believed there is a reasonable chance that users of the given iterables would want to perform these class-specific operations in addition to the iterator operations.

Roadmap

  • ~~XSet~~ provided as of v1.0.0
  • XMap
  • XWeakSet?
  • XWeakMap?

License

MIT

Copyright (c) 2019 Kyle Lin