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

eemit

v1.0.2

Published

Event emitter micro library for Node and the browser

Downloads

3

Readme

eemit

Event emitter micro library for Node and the browser

Build status Code Climate Test Coverage

Attach event handlers easily on arbitrary objects or classes – or have an emitter on its own.

Browser support

Browser matrix

Eemit can be run out of the box on most modern browsers and IE9+.

Usage

Eemit is written using ES6 (ES2015) syntax and aimed for use in modern modular JavaScript applications built with bundlers. The module is bundled in an UMD module format so eemit can be loaded via a traditional script tag.

Installation

Install via npm.

npm i -S eemit

To load the module in a standard script tag use the minified version from the dist folder.

Bundlers that transpile ES6 code can alternatively load src/eemit.js, e.g for Rollup users a "jsnext:main" field is provided.

Initialise

The module 'eemit' returns a single function after import.

import eemit from 'eemit';

When called without arguments, returns an object with API methods.

// Create an empty emitter.
const emitter = eemit();

When called on an object, it returns the object extended with API methods.

// Extend an already defined object by adding event handler methods.
const obj = {foo: 'bar'};
const emitterObject = eemit(myObject);

When called on a class, it returns a new class extending the original.

// Extend an existing class to ensure every instance can have events.
class myClass {
  constructor(bar) {
    this.foo = bar;
  }
}

// Extend the class with emitter capabilities.
const emitterClass = eemit(myClass);

// Instantiate.
const emitterInstance = new emitterClass('baz');

API

on('name', handler)

Attach an event handler function for a new or existing event to the emitter.

const handler = () => {
  // Handler code here
};

// Attach handler to an event.
emitter.on('name', handler);

off('name', handler)

Detach an event handler function for a new or existing event to the emitter. If handler is not specified, all handlers are removed from named event.

// Detach the specified handler from the event.
emitter.off('name', handler);

// Detach all handlers from the event.
emitter.off('name');

once('name', handler)

Attach an event handler function ensuring that the handler will only be called once.

emitter.once('name', handler);

trigger('name', [arguments])

Trigger an event. This executes all previously attached handlers to the event. Any arguments present will be passed along to the handlers.

// Trigger an event without arguments.
emitter.trigger('name');

// Trigger an event with arguments.
const handler = (list = [], foo = '') => {
  // handler code here
};
emitter.on('name', handler);
emitter.trigger('name', [1, 2 ,3], 'bar');

Contributing

If you find an bug please open an issue.

Pull requests for bug fixes are also welcome, however in order to keep the library minimalistic I do not plan to introduce new features at the moment.

This project uses standard npm scripts to run the build and tests. Tests for Node are run by Mocha and browser tests are run by Karma on browsers provided by SauceLabs. Code coverage is reported via Istanbul and the coverage report is published on Code Climate via Travis build runs.

Install the development environment

To install the development dependencies, make sure you have Node.js installed, then run npm install in the project folder to install all development dependencies.

Running tests

Code style is enforced via eslint. To run it use npm run test:lint.

To run tests for Node, use npm run test:node.

To run tests for the browser you need to have a SauceLabs account. A SauceLabs user name and an access key needs to be set in order to run the tests. These can be set in SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables or by creating a sauce.json file in the repository root folder with the following contents.

{
  "username": "your-sauce-username",
  "accessKey": "your-sauce-access-key"
}

Once set up, use npm run test:browser to run the suite on all browsers.

License

Copyright 2016 Attila Beregszaszi, MIT licensed, see LICENSE for details.