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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sahnee/eventemitter

v2.0.0

Published

Yet another eventemitter

Downloads

1

Readme

@sahnee/eventemitter

Yet another EventEmitter

Features

  • Classic subscription based event emitter class
  • Observer pattern
  • Written in TypeScript
  • Fully unit tested

EventEmitter

The EventEmitter is the main usage of this library. You can either use it as a standalone class instance of inherit your own classes form it.

It features all basic functions of an event emitter:

import EventEmitter from '@sahnee/eventemitter';

const ee = new EventEmitter();
ee.on('my-event', args => console.log('Event:', args));
ee.emit('my-event', 1);
ee.emit('my-event', 2);
// Prints:
// - Event: 1
// - Event: 2

All supported functions and properties are. Parameters marked with ? are optional:

  • prefix - A prefix used for non symbol events to avoid e.g. prototype pollution. By default '~'.
  • eventNames() - The names of all currently registered events.
  • listeners(event) - Gets all listeners of the given event.
  • listenerCount(event) - Gets amount of listeners for the given event.
  • emit(event, ...args) - Emits the given event and invokes all handlers for it.
  • addEventListener(event, fn, context?, once?, priority?) - Adds an event listener to the given event. Options are:
    • context - What this will refer to in your callback.
    • once - If this is true the event handler will once be invoked once.
    • priority - The priority of the event handler. See the numeric Priority enum for recommended base values.
  • on(event, fn, context?, priority?) - Alias for addEventListener(event, fn, false, context, priority).
  • once(event, fn, context?, priority?) - Alias for addEventListener(event, fn, true, context, priority).
  • removeListener(event, fn?: ListenerFn, context?, once?, priority?) - Removes a event handler again.
  • off(event, fn?: ListenerFn, context?, once?, priority?) - Alias for removeListener with the same parameters.
  • removeAllListeners(event?) - Removes either all listeners of the entire emitter or just for the given event.

Observer

The observer pattern is currently not part of the stable public API. Usage is therefore discouraged.