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

@szilanor/stream

v3.3.2

Published

Typesafe API for processing iterable data in TypeScript and JavaScript

Readme

Stream API

Type-safe, lazy data processing for TypeScript and JavaScript. Inspired by Java Streams, C# LINQ, and Kotlin Sequences.

Read the Documentation

Installation

npm install @szilanor/stream

Quick Start

Stream API creates a pipeline where data flows through operations. It is lazy, meaning items are processed one by one, and only if needed.

import { stream, filter, map, toArray } from "@szilanor/stream";

const result = stream([1, 2, 3, 4, 5])
  .pipe(
    filter((x) => x % 2 === 0),
    map((x) => x * 10),
  )
  .collect(toArray());

console.log(result); // [20, 40]

Why use this?

  • Lazy Evaluation: Avoids creating intermediate arrays. Great for large datasets or performance-critical paths.
  • Type Safety: Infers types correctly through complex pipelines.
  • Async Support: Native support for AsyncIterable and async transformations.
  • Lightweight: Zero dependencies and tree-shakeable.

How it Works

Under the hood, Stream API uses JavaScript Itarator and Generators.

When you call .pipe(), you aren't iterating the data yet. You are composing a chain of generator functions. Iteration only begins when you call .collect() (or iterate the stream manually). This is what allows for efficiency gains:

  1. Short-circuiting: Operations like find or take stop the generator chain early.
  2. Low Memory: Only one item is held in memory at a time (unless buffering is explicitly required, like in sort).

Examples

Laziness (Performance)

Standard array methods like .map().filter() create a new array for every step. Stream API does not.

import { stream, map, filter, take, toArray } from "@szilanor/stream";

// Standard JS: Iterates the entire array multiple times
const bad = hugeArray
  .map(transform) // Allocates new array size of hugeArray
  .filter(predicate) // Allocates another new array
  .slice(0, 5);

// Stream API: Iterates once, stops early
const good = stream(hugeArray)
  .pipe(
    map(transform),
    filter(predicate),
    take(5), // Stops processing after finding 5 items
  )
  .collect(toArray());

Async Pipelines

Handling async data streams seamlessly.

import { stream, mapAsync, filterAsync, toArrayAsync } from "@szilanor/stream";

const activeUsers = await stream(userIds)
  .pipeAsync(
    mapAsync(async (id) => {
      const user = await fetchUser(id);
      return user;
    }),
    filterAsync((user) => user.isActive),
  )
  .collectAsync(toArrayAsync());

Custom Operators

Extending the library is as simple as writing a generator function.

import { OperationFunction, stream, toArray } from "@szilanor/stream";

// Emit every Nth item
const everyNth = <T>(n: number): OperationFunction<T, T> => {
  return function* (iterable) {
    let i = 0;
    for (const item of iterable) {
      if (i++ % n === 0) yield item;
    }
  };
};

stream([1, 2, 3, 4, 5, 6]).pipe(everyNth(2)).collect(toArray()); // [1, 3, 5]

Comparison

| | Stream API | RxJS | Native Array Methods | | ------------- | --------------------------------- | ------------------------ | -------------------- | | Paradigm | Pull-based (Iterators) | Push-based (Observables) | Eager | | Data Type | Data in motion / Collections | Events / Time streams | Static Arrays | | Async | AsyncIterable (await/for-await) | Observables (subscribe) | Promise.all needed |

Understanding "Data Types"

The main difference lies in who controls the flow:

  • Stream API (Pull): You are in control. You ask for the next item when you are ready. This is ideal for "Data in motion" (reading files, database cursors, large algorithms) where you want to process data at your own pace without being overwhelmed.
  • RxJS (Push): The source is in control. Data arrives whenever it wants (mouse clicks, WebSocket messages, timers). You must react to it immediately.
  • Native Arrays: Data is static. It sits in memory, allowing random access (index [0]), but requiring all data to be loaded before processing begins.