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

emit.js

v0.5.1

Published

Efficient minimalist event emitter in JavaScript.

Downloads

6

Readme

emit.js Build Status

Efficient minimalist event emitter in JavaScript.

Installation

It is available with bower or npm:

bower install emit.js
npm install emit.js

Include emit.min.js to the HTML, and the emit object is now available in the global scope:

<script type="text/javascript" src="/path/to/bower_components/emit.js/dist/emit.min.js"></script>

Alternately, you can use a module manager to avoid global scoping:

var emit = require('emit.js');
// or es6 import
import emit from 'emit.js';

Usage

Create an event emitter

var emitter = emit();

Register listener on it

You can register a listener with on and once method. Listeners registered with once will be triggered only once.

emitter.on('event', function(...args) {
    // the args depends on the emit call
    
    console.log('I am a listener');
});

// you can also register an event with a regex
emitter.on(/^event(foo)?$/, function(...args) {
    // the args depends on the emit call
    
    console.log('I am a listener');
});

// you can also register an event with a callback for powerful listener
emitter.on(function(event) {
    return event.substr(0, 5) === 'hello'; // We want to match all event beginning with `hello`.
}, function(...args) {
    // the args depends on the emit call
    
    console.log('I am a listener');
});

emitter.once('event', function(...args) {
    console.log('I am triggered only once');
});

Unregister a listener

When you register a listener, you get in return a callback to unregister it:

var unregister = emitter.on('event', function(...args) {
    // the args depends on the emit call
    if (...) {
        unregister(); // unregistering this listener
    }

    console.log('I am a listener');
});

Emit an event

To emit an event, just use the emit method:

emitter.emit('event', arg1, arg2, ...); // we emit an event with as many parameters as we want

emitter.emit('event').then(function() {
    // all listeners have been called
}, function(error) {
    // an error occured
});

Removing all listeners

You can remove all listeners by calling the removeAllListeners method.

Development

Installation

make install

Build

make build or make build-dev (unminified version)

Watch

make watch

Test

make test

Contributing

All contributions are welcome and must pass the tests. If you add a new feature, please write tests for it.

License

This application is available under the MIT License.