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

obgen

v0.5.2

Published

Javascript Observables implemented with async generators

Readme

Obgen

Observable (reactive streams) pattern implemented using es2015 async generators.

Installation

Using yarn:

yarn add obgen

or using npm:

npm i --save obgen

Usage

Observables are lazy streams of data that emit items asynchronously. They may be infinite or include an optional terminal event to signal the end of the stream. You can map, filter, etc.:

import Observable from "obgen/observable";
import { asyncDefer, buffer, empty, from, just, promise, wrap } from "obgen";

const arr = [...Array(num).keys()].map((_, i) => i);
const observable = from(arr)
  .map((i) => i * 2)
  .filter((i) => i % 2 == 0)
  .take(10);

Observables are lazily evaluated. Items are not collected until you subscribe to them:

observable.subscribe(console.log);
// outputs:
// 0
// 2
// 4
// 6
// 8
// 10
// 12
// 14
// 16
// 18

If you prefer, you can instead iterate it with for-await as you normally would:

for await (const element of observable.iterable()) {
  console.log(element);
}

Or collect the items into an array:

const array = await observable.toArray();

Observables can be created in multiple ways. For example, you can manually wrap an async generator function (which is not particularly useful by itself):

const observable = wrap(async function* () {
  yield "a";
  yield "b";
  yield "c";
});

You can also use buffer() to accumulate items until subscription time:

const observable = buffer((stream) => {
  stream.emit(1);
  stream.emit(2);
  stream.emit(3);
  stream.emit(4);
  stream.end();
});

Or asynchronously emit items:

const observable = buffer((stream) => {
  // delay emission for a few milliseconds so that it happens after we subscribe
  times(5, (i) => setTimeout(() => stream.emit(i), i * 100));
  setTimeout(() => stream.end(), 600);
});
expect(await observable.toArray()).toEqual([0, 1, 2, 3, 4]);

Releasing

  • Bump the version in package.json
  • Run npm publish
  • Create a git tag with the new version and changelog

License

MIT