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

erre

v3.0.1

Published

Modern, performant and tiny streams script using generators

Downloads

323

Readme

Build Status

NPM version NPM downloads MIT License

Description

Erre is a modern, performant and tiny (~0.5kb minified) streams script using generators that runs on modern browsers and node. It can be used to manage any kind of sync and async event series and it's inspired to bigger libraries like:

Installation

npm i erre -S

Usage

You can use it to create and manipulate simple event streams

import erre from 'erre'

const stream = erre(
  string => string.toUpperCase(),
  string => [...string].reverse().join('')
)

stream.on.value(console.log) // EVOL, ETAH

stream.push('love')
stream.push(async () => await 'hate') // async values

It supports async and sync event chains thanks to ruit

const userNamesStream = erre(
  async user => await patchUsers(user), // async function returning a users collection
  users => users.map(user => user.name)
)

userNamesStream.on.value(console.log) // ['John'...]

userNamesStream.push({
  name: 'John',
  role: 'Doctor',
  age: 24
})

API

erre(...functions)

@returns stream

Create an erre stream object. The initial functions list is optional and it represents the chain of async or sync events needed to generate the final stream output received via on.value callbacks

stream

It's an enhanced Generator object having additional API methods

stream.push(value)

@returns stream

Push a new value into the stream that will be asynchronously modified and returned as argument to stream.on.value method

const stream = erre()
stream.on.value(console.log) // 1
stream.push(1)

stream.on.value(callback)

@returns stream

Add a callback that will be called receiving the output of the stream asynchronously

const stream = erre(val => val + 1)

stream.on.value(console.log) // 2
stream.on.value(val => console.log(val * 2)) // 4

stream.push(1)

stream.on.error(callback)

@returns stream

Add a callback that will be called in case of errors or promise rejections during the output generation

const stream = erre(val => {
  throw 'error'
})

stream.on.value(console.log) // never called!!
stream.on.error(console.log) // 'error'

stream.push(1)

stream.on.end(callback)

@returns stream

Add a callback that will be called when the stream will be ended

const stream = erre()

stream.on.end(() => console.log('ended!')) // ended!

stream.end()

stream.off.value(callback)

@returns stream
@throws Error if callback isn't registered

Removes a previously-registered callback

const stream = erre()

const handler = (value) => console.log('handling', value)
stream.on.value(handler)
stream.push(1) // handler called, logs: handling 1

stream.off.value(handler)
stream.push(2) // handler is not called

// throws, because the handler is not registered
const someOtherHandler = () => console.log(`don't register me`)
stream.off.value(someOtherHandler)

stream.off.error(callback)

@returns stream
@throws Error if callback isn't registered

stream.off.end(callback)

@returns stream
@throws Error if callback isn't registered

stream.connect(function)

@returns stream

Enhance the stream adding a new operation to the functions chain to generate its output

const stream = erre(val => val + 1)

stream.on.value(console.log) // 2, 4
stream.push(1)

// enhance the stream
stream.connect(val => val * 2)
stream.push(1)

stream.end()

@returns stream

End the stream

const stream = erre(val => val + 1)

stream.on.value(console.log) // 2
stream.push(1)

// end the stream
stream.end()

// no more events
stream.push(1)
stream.push(1)
stream.push(1)

stream.fork()

@returns new stream object

Create a new stream object inheriting the function chain from its parent

const stream = erre(val => val + 1)

stream.on.value(console.log) // 2, 3
stream.push(1)

const fork = stream.fork()
fork.on.value(console.log)
fork.connect(val => val * 10) // 20, 60

// 2 independent streams
fork.push(1)
stream.push(2)
fork.push(5)

stream.next(value)

@returns { done: true|false, value: Promise|undefined }

Run a single stream sequence (without dispatching any event) returning as value a promise result of the stream computation. If the stream was ended the done value will be true and the value will be undefined.

const stream = erre(val => val + 1)

stream.on.value(console.log) // never called

const { value } = stream.next(1)

value.then(console.log) // 2

erre.cancel()

Static function that if returned by any of the stream functions chain can be used to filter or stop the computation

const stream = erre(val => {
  if (typeof val !== 'number') return erre.cancel()
  return val + 1
})

stream.on.value(console.log) // 2, 3
stream.push(1)
stream.push('foo') // filtered
stream.push('1') // filtered
stream.push(2)

erre.off()

Static function that if returned by any of the subscribed callbacks can be used to unsubscribe it

const stream = erre(val => val + 1)

stream.on.value(val => {
  // if this condition will be matched, this callback will be unsubscribed
  if (typeof val !== 'number') return erre.off()
  console.log(val)
}) // 2
stream.push(1)
// this value will let the previous listener unsubscribe itself
stream.push('foo')
stream.push('1')
// this value will not be logged because the stream.on.value was unsubscribed
stream.push(2)

erre.install(name, fn)

@returns erre

Extend erre adding custom API methods. Any plugin must have at lease a name (as string) and a function

// alias the `console.log` with `erre.log`
erre.install('log', console.log)

const stream = erre(val => val + 1)

stream.on.value(erre.log) // 2, 3
stream.push(1)
stream.push(2)

TODO List