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

@nabilk/minemit

v1.0.11

Published

A minimal event emitter

Downloads

4

Readme

minemit

A minimal event emitter

license npm

Installation and basic usage

Install via npm

$ npm i minemit

Either import minemit completely or just the desired method

import minemit, { add, emit } from "minemit";

Once imported, there is no need to create any instances. Minemit allows you to register multiple listeners for a given event and emit it.

function myCallback(params) {
    // code...
}

add("myEvent", myCallback);

// ...

emit("myEvent");

You can also pass down arguments to the event you are emitting. Those will be accessible to all registered listeners.

function myCallback({ prop }) {
    console.log(prop); // foo

    // code...
}

add("myEvent", myCallback);
emit("myEvent", { prop: "foo" });

Minemit also allows you to emit an event asynchronously with the emitAsync method. Basically all the listeners registered to that event will be treated as promises, giving you the possibility to wait for the whole listeners stack to complete. Here is an example.

function myCallback() {
    // code...
}

async function myAsyncFunction() {
    // code...
}

add("myEvent", myCallback);
add("myEvent", myAsyncFunction);

await emitAsync("myEvent");

// code will be executed after the listeners stack has finished...

Functions

add ⇒ function

Adds a listener to a given event.

Returns: function - Returns the newly added listener

| Param | Type | Description | | -------- | --------------------- | --------------------------------- | | event | string | The name of the event | | listener | function | The listener that you want to add |

addOnce ⇒ void

Adds a listener that gets fired once to a given event.

| Param | Type | Description | | -------- | --------------------- | --------------------------------- | | event | string | The name of the event | | listener | function | The listener that you want to add |

prepend ⇒ function

Adds a listener to a given event. The listener is added to the first position of the stack.

Returns: function - Returns the newly added listener

| Param | Type | Description | | -------- | --------------------- | --------------------------------- | | event | string | The name of the event | | listener | function | The listener that you want to add |

prependOnce ⇒ void

Adds a listener to a given event. The listener is added to the first position of the stack and that gets fired once.

| Param | Type | Description | | -------- | --------------------- | --------------------------------- | | event | string | The name of the event | | listener | function | The listener that you want to add |

remove ⇒ void

Removes a listener from a given event.

| Param | Type | Description | | -------- | --------------------- | --------------------------------- | | event | string | The name of the event | | listener | function | The listener that you want to add |

clear ⇒ void

Clears the listeners stack of the given event.

| Param | Type | Description | | ----- | ------------------- | --------------------- | | event | string | The name of the event |

emit ⇒ void

Fires all the listeners of the given event.

| Param | Type | Description | | ------ | ------------------------- | ------------------------------------------------------- | | event | string | The name of the event | | params | arguments... | The optional arguments that will be passed to listeners |

emitAsync ⇒ Promise

Fires all the listeners of the given event. The listeners get all treated as promises in order to get fired asyncronously.

Returns: Promise - The listeners stack

| Param | Type | Description | | ------ | ------------------------- | --------------------- | | event | string | The name of the event | | params | arguments... | The name of the event |

list ⇒ Array

Returns the listeners stack of the given event.

Returns: Array - The listeners stack

| Param | Type | Description | | ----- | ------------------- | --------------------- | | event | string | The name of the event |