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

straemjs

v2.0.0

Published

Straem is a minimal wrapper for the custom event browser API.

Downloads

5

Readme

Stræm

Stræm is a minimal wrapper for the Custom Event API.

🚀 Getting started

To use Stræm with npm and/or a bundler such as webpack or rollup, install it via yarn or npm:

yarn add straemjs
# or use npm
npm install straemjs

You can also use it directly in the browser and include it via CDN (or locally, if you like).

<head>
    ...
    <!-- as a local file -->
    <script src="./your/path/to/straem.browser.min.js"></script>
    <!-- or via CDN -->
    <script src="http://unpkg.com/straemjs"></script>
    ...
</head>

🔧 Usage

Imports and Global

Stræm provides exports for modern import syntax as well as exports for the require syntax.

// node require syntax
const { receive, dispatch } = require('straemjs');

// modern es6 style syntax
import { receive, dispatch } from 'straemjs';

In case you included the Stræm file via CDN, the straem object is globally available.

const { receive, dispatch } = straem;

Creating a custom event listener

To receive and listen to custom (or built-in) event, use the receive() method

import { receive } from 'straemjs';

// Use the receive method to register one or more event names for the listener

const listener = receive('custom-event', 'another-event');

// You can use the 'from' method to set the target of the event

const listener = receive('custom-event').from(window);

// To create the listener(s) and register a callback, use the 'then' method returned by
// either the 'receive' or 'from' method and pass a handler and an optional opinions object.
// The method returns a function to remove the created listener(s).

const dispose = receive('custom-event').then(handler, eventInit);

Dispatching a custom event

To dispatch a custom event, use the dispatch() method.

import { dispatch } from 'straemjs';

// Use the dispatch method to register one ore more event names for dispatching.
// As with the receive method, you can chain the from method to set the target.

const send = dispatch('custom-event').from(window);

// Use the 'with' method to dispatch the event with a given payload.

send.with({ hello: 'world' });

API

receive()

Type: receive(...string: string[]) => { from: Function, then: Function, eventTarget: EventTarget, eventNames: string[] }

The receive method is used to create a custom event listener. Pass any number of strings as argument. The method returns the Receiver object, containing the from(), then(), eventTarget & eventNames properties.

dispatch()

Type: dispatch(...string: string[]) => { from: Function, with: Function, eventTarget: EventTarget, eventNames: string[] }

The dispatch method is used to create a custom event dispatcher. Pass any number of strings as argument. The method returns the Dispatcher object, containing the from(), with(), eventTarget & eventNames properties.

Receiver.from() / Dispatcher.from()

Type: from(eventTarget: EventTarget) => { this }

The from method is used to set the eventTarget of the receive()of dispatch() methods. The method will return the receive of dispatch object, respective of the method that it was called from.

Receiver.then()

Type: then<T>(action: Action<T>, eventInit?: AddEventListenerOptions) => function

The then method is used to execute the specified handler function when the custom event is received. The method takes a eventInit object as second parameter, which is equal to the options provided by the Event interface. The method returns a function to remove all created listeners.

Dispatcher.with()

Type: with(payload?: any, eventInit?: EventInit) => void

The with method is used to dispatch the created event from the dispatch() method with a specified payload. The method takes a eventInit object as second parameter, which is equal to the options provided by the Event interface. The payload will default to undefined if not specified.

Contributing

If you would like to contribute, take a look at the contribution guide.

License

Stræm.js is licensed under the MIT License