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

js-fast-emitter

v1.0.13

Published

Javascript Fast Emitter

Downloads

6

Readme

js-fast-emitter

Description

js-fast-emitter is a lightweight npm library written in TypeScript that provides event emitter functionality. It allows you to easily manage and trigger events in your JavaScript applications.

Installation

You can install js-fast-emitter using npm:

npm install js-fast-emitter

Usage

To use js-fast-emitter, import the Emitter class from the package:

import Emitter from "js-fast-emitter"

Next, initialize a new instance of Emitter:

const AppEmitter = new Emitter();

Methods

add(eventName: string, listener: Function, options?: { once?: boolean, delay?: number }): void

Adds a listener function for the specified event name.

  • eventName (string): The name of the event to listen for.
  • listener (Function): The listener function to be called when the event is emitted.
  • options (object, optional): Additional options for the listener.
    • once (boolean, optional): If set to true, the listener will trigger once and then be automatically removed. Defaults to false.
    • delay (number, optional): The delay in milliseconds before the listener is triggered. Defaults to 0.

Returns: An object with a remove function that can be used to remove the added listener.

Example:

// Listener triggered only once
AppEmitter.add('myEvent', (data) => {
  console.log('Event emitted:', data);
}, { once: true });

// Listener triggered with a delay of 1000 milliseconds
AppEmitter.add('myEvent', (data) => {
  console.log('Delayed event emitted:', data);
}, { delay: 1000 });

// Assign the listener to a const to remove it
const listener = AppEmitter.add('myEvent', (data) => {
  console.log('Event emitted:', data);
});

// Removing the listener
listener.remove();

emit(eventName: string, params: any): void

Emit a listener function for the specified event name.

  • eventName (string): The name of the event to listen for.
  • params (any): The listener params when the event is emitted.

Example:

AppEmitter.emit('myEvent', { message: "Hello World!" });

getAllListeners(eventName?: string): Function[]

Returns an array of listener functions for the specified event name. If no event name is provided, it returns all listener functions for all events.

  • eventName (string, optional): The name of the event to get the listeners for.

Example:

const listeners = AppEmitter.getAllListeners('myEvent');
console.log(listeners); // [Function]