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

signal-js

v3.0.1

Published

a small, simple es6 event system.

Downloads

918

Readme

signal-js

A small (2.4KB minified, 1.07KB gzipped) and fast event system with 0 dependencies. Written in es2020 and built for performance. Great as a pubsub or to add event emitters to your code.

Installation

npm install signal-js

How to use

Add a function to signal using on and trigger the function using emit

import signal from 'signal-js';

signal.on('basic', arg => console.log(arg);

signal.emit('basic', 1);
// > 1

Add multiple functions to the same event name

import signal from 'signal-js';

signal.on('multiple', () => console.log(1));
signal.on('multiple', () => console.log(2));
signal.on('multiple', () => console.log(3));

signal.trigger('multiple');
// > 1
// > 2
// > 3

Pass as many parameters as you need

import signal from 'signal-js';

signal.on('params', (one, two, three) => console.log(one, two, three));

signal.emit('params', 1, 2, 3);
// > 1 2 3

Remove events using off

import signal from 'signal-js';

signal.on('test', () => console.log('hi'))
  .off('test') // removes all `test` events
  .emit('test'); // nothing happens

once can also be used

import signal from 'signal-js';

let idx = 0;
signal.once('tick', () => idx++);

signal.emit('tick')
// idx = 1

signal.emit('tick');
// idx = 1

The exposed signal is a singleton, but other instances can also be created:

import signal from 'signal-js';

signal.on('foo', () => console.log('global'));

const local = signal();
local.on('foo', () => console.log('local'));

const local2 = local();
local2.on('foo', () => console.log('local2'));

signal.emit('foo');
// > "global"

local.emit('foo');
// > "local"

local2.emit('foo');
// > "local2"

API

.on(eventName, listener)

  • eventName string The name of the event
  • listener Function The event handler
  • Returns: signal

Alias: addListener, subscribe, bind

.off(eventName, listener)

  • eventName string The name of the event
  • listener Function (optional) The event handler
  • Returns: signal

If listener is passed, the specific listener will be unbound, otherwise all listeners under eventName will be unbound.

Alias: removeListener, unsubscribe, unbind

.emit(eventName, [...parameters])

  • eventName string The name of the event
  • parameters any (optional) The arguments passed to the listener
  • Returns: signal

Alias: dispatch, trigger

.once(eventName, listener)

  • eventName string The name of the event
  • parameters any The event handler
  • Returns: signal

Adds a one-time listener that will remove itself after being invoked.

.listeners(eventName)

  • eventName string The name of the event
  • Returns: Array

Retrieves registered listeners under the eventName. If no eventName is passed, returns all listeners.

.keys()

  • Returns: Array

Retrieves all eventNames.

.size(eventName)

  • eventName string The name of the event
  • Returns: Number

Returns the quantity of listeners at the given eventName. If no eventName is passed, returns the quantity of all listeners.

.clear(eventName)

  • Returns: signal Forcefully clears all listeners and eventNames from the signal at the eventName. Clears all listeners if no eventName is passed.