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

tiny-eventer

v0.2.0

Published

A small event subscrubtion system.

Downloads

8

Readme

tiny-eventer

Tiny and simple event module with no third party dependencies.

Usage

Installation

Using npm:

npm install tiny-eventer [--save]

Using yarn:

yarn add tiny-eventer

In Node.js:

'use strict'

// Load a global instance
var eventer = require('tiny-eventer');

// Or load the Eventer class to use a new instance of it.
var Eventer = require('tiny-eventer').Eventer;

In the browser:

// eventer is a global object, attached on window.eventer
eventer === window.eventer;
// true

// Get the eventer class to for creating new instances
var Eventer = eventer.Eventer;

API

eventer.on(eventName, listener, [_this])

Subscribes to events on eventName.

eventName (String) Name of the event to listen for

listener (Function) The function to be called. Any params passed into trigger(eventName, [...params]) will be passed in.

[_this (Any)] A reference to this (or an ID of sorts) which can be used for unsubscribing to events when listener is an anonymous function. This can be used to group event listeners, as string or number could be passed in.

Example

/** ... */

// Passing in a named function and skipping *_this*
eventer.on('user_added', onAddedUser);

function onAddedUser(user) {
  console.log('user_added event!');
}

// Passing in an anonymous function with a string ID as *_this*.
eventer.on('other_user_added', function (user) { console.log('other_user_added event!') }, 'some.id');

/** ... */

eventer.once(eventName, listener, [_this])

Subscribes to a single event on eventName. Only difference between eventer.once and eventer.on is that eventer.once will only fire once, as is suggested by the name of the function.

Events subscribed to using once are cancellable using eventer.off(...).

eventName (String) Name of the event to listen for

listener (Function) The function to be called. Any params passed into trigger(eventName, [...params]) will be passed in.

[_this (Any)] A reference to this (or an ID of sorts) which can be used for unsubscribing to events when listener is an anonymous function. This can be used to group event listeners, as string or number could be passed in.

Example

/** ... */

// Passing in a named function and skipping *_this*
eventer.once('user_added', onAddedUser);

function onAddedUser(user) {
  console.log('user_added event!');
}

eventer.trigger('user_added', { userId: 1, name: 'Arthur Dent' });
// Logs 'user_added event!'

eventer.trigger('user_added', { userId: 2, name: 'Ford Prefect' });
// Logs nothing

/** ... */

eventer.off(eventName, listener, [_this])

Unsubscribes to events on eventName.

eventName (String) Name of the event to stop listening for

[listener (Function)] The function which would've been called. Either this _this can be used to match an event listener.

[_this (Any)] A possible other identification for when listener is an anonymous function, or if a group of events should be unsubscribed with a single call.

Example

/** ... */

// Unsubscribe by passing in a named function and skipping *_this*
eventer.off('user_added', onAddedUser);

function onAddedUser(user) { /** ... */ }

// Unsubscribe by passing in a string ID as *_this* and leaving *listener* empty
eventer.off('other_user_added', undefined, 'some.id');

/** ... */

eventer.clear(eventName)

Unsubscribes all listeners on eventName

eventName (String) Name of the event to remove all listeners from

Example

/** ... */

// Unsubscribe all listeners
eventer.clear('user_added');

/** ... */

eventer.clearAll()

Removes all listeners from all events

Example

/** ... */

// Remove all listeners
eventer.clearAll();

/** ... */

eventer.trigger(eventName, [...params])

Triggers an event with the passed in parameters, if any.

eventName (String) Name of the event to trigger

[...params (Any)] Parameters to be passed into callbacks

/** ... */

var newUser = {
  id: 42,
  name: 'Arthur Dent',
  occupation: 'Hapless Englishman'
};

var otherUser = {
  id: 49,
  name: 'Ford Prefect',
  occupation: 'Writer'
};

// Triggers an event with no parameters passed into it.
eventer.trigger('look_no_params_ma');

// Trigger event with a single parameter passed in (other than eventName, obviously).
eventer.trigger('user_added', newUser);

// Trigger event with multiple parameters passed in. Any number of parameters can be passed in.
eventer.trigger('users_added', newUser, otherUser);

/** ... */

eventer.$events

Container object for events, with keys as the name of the event and the values are arrays of event items (consisting of listener and _this)

new eventer.Eventer()

Creates a new Eventer instance useful for creating sandboxed events.

/** ... */

var _eventer = new eventer.Eventer();

_eventer === eventer;
// false

_eventer instanceof eventer.Eventer;
// true

eventer instanceof eventer.Eventer;
// true

/** ... */