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

events-merge

v1.2.1

Published

A small tool for merging EventEmitters.

Downloads

1

Readme

events-merge v1.2.1

Travis npm

A small utility for merging two+ EventEmitters together.

Installing

$ npm install --save events-merge

Testing

$ cd events-merge
$ npm install --only=dev
$ npm test

Getting Started

var merge   = require('events-merge');
var Emitter = require('events').EventEmitter;

var counter = 0;
var base = new Emitter();
var emitters = [
  new Emitter(),
  new Emitter()
];

base.on('inc', () => { counter++ });
emitters[0].on('inc', () => { counter++ });
emitters[1].on('dec', () => { counter-- });

merge.to(base).emitters(emitters);

base.emit('inc'); // counter == 2
base.emit('inc'); // counter == 4
base.emit('dec'); // counter == 3

or simply

var merge = require('events-merge').merge;

// code code code...

merge(base, emitter1, emitter2, ...); // base is now merged with the given emitters.

Using the es6 flavor

merge uses the es5 syntax by default. If your node.js version does not support es6 syntax, you can overcome this problem by requiring events-merge/es5 lib instead.

var merge = require('events-merge/es6');

NOTICE that require('events-merge/es6').merge shortcut DOESN'T work, so use the es6 flavor only with the oop api.

API

merge.set(key:String, value) : self

Sets a default option for the events-merge module.

merge.set('overwrite', true);

merge.base(emitter:Emitter) : self

Sets a base emitter to merge other emitters to.

merge.base(emitter).emitters(emitter1, emitter2, ...);

merge.to(emitter:Emitter) : self

Alias to merge.base.

merge.to(emitter).merge(emitter1, emitter2, ...);

merge.merge(...emitters:Emitter) : Emitter

merge.merge(emitters:Array) : Emitter

Merge the given emitters (by array or by seperated param) to the base emitter. If not base emitter given, uses the first emitter in the given emitters list.

var merge = require('events-merge').merge;
merge(base, emitter1, emitter2, ...); // base is now merged with the given emitters.

merge.emitters(...emitters:Emitter) : Emitter

merge.emitters(emitters:Array) : Emitter

Alias for merge.merge.

[getter] merge.overwrite

Sets the overwrite flag to true.

merge.overwrite.to(base).merge(emitter1, emitter2, ...);

[static] merge.eventNamesOf(emitter:Emitter) : Array

A helper method that returns list of event names that a given emitter holds.

emitter.on('ev1', someMethod);
emitter.on('ev2', anotherMethod);

console.log(merge.eventNamesOf(emitter)); // prints ['ev1', 'ev2'].

LICENSE

MIT


Yo! Follow me on GitHub @amit3vr. You might find my shit useful someday.