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

stupidly-simple-events

v1.0.0

Published

Stupidly simple events

Readme

events.js

Stupidly simple events.

I found myself writing this code over and over again, so figured I'd zip it up in a library and save myself the trouble of doing it again. Just about 430 bytes gzipped (don't worry, there aren't any dependencies either), events.js implements a -- stupidly simple, and appropriately tiny -- event interface.

How simple? This simple.

var events = Events();

events.on( 'cupcake', function () {
	alert( 'yum!' );
} );

events.fire( 'cupcake' );

// yum!

Just four simple methods:

  • on()
  • one()
  • off()
  • fire()

They do... what you would expect them to do.

API documentation

Events.prototype.on( eventName, handler )

Parameters:

  • eventName {string}
  • handler {function}

Attaches a handler a given event. When the event is fired, (surprise suprise) the handler will be called.

events.on( 'cookie', function ( cookie ) {
	eat( cookie );
} );

events.on( 'full', function () {
	stopEating();
} );

Events.prototype.one( eventName, handler )

Parameters:

  • eventName {string}
  • handler {function}

Like .on(), but with a twist – the handler is only called once. If eventName is fired subseqent times, the handler won't be called again.

events.one( 'bloated', function () {
	die();
} );

Events.prototype.off( eventName[, handler] )

Parameters:

  • eventName {string}
  • handler {function} (optional)

This function is used to remove event handler(s). If you would like to remove all event handlers attached to a particular event, use:

events.off( 'cookie' );

If you only want to remove one specific handler:

var handler = function () { alert( 'yay!' ) };
events.on( 'cookie', handler );

[...]

events.off( 'cookie', handler );

Events.prototype.fire( eventName[, arguments] )

Parameters:

  • eventName {string}
  • arguments {...mixed} (optional)

Trying to fire an event? You're in luck! In its simplest form:

events.fire( 'cheese' );

This calls all handlers previously attached to the cheese event using .on() (and .one()) with no arguments. If you want to pass arguments...

events.on( 'cookie', function ( cookie ) {
	eat( cookie );
} );

[...]

var cookie = new Cookie();
events.fire( 'cookie', cookie );

You can pass an unlimited number of arguments – that's right, knock yourself out!

Bonus feature

You can restrict the names of events available by passing in an array when initializing:

var limitedEvents = Events( [ 'joy', 'celebration' ] );

limitedEvents.on( 'death', function () {
	alert( ':(' );
} );
// Error: The event "death" is not defined

If you later attempt to fire or add a handler to an event that wasn't in the initial array, an error will be thrown.