Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eventemitter2

Package Overview
Dependencies
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventemitter2

A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.

  • 6.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.8M
decreased by-52.45%
Maintainers
2
Weekly downloads
 
Created

What is eventemitter2?

The eventemitter2 npm package is an implementation of the EventEmitter module found in Node.js. It provides an interface for implementing event-driven architecture. It allows you to create objects that can emit named events that cause function objects ('listeners') to be called. It offers several enhancements over the native EventEmitter, such as namespaces, wildcards, and the ability to listen to all events.

What are eventemitter2's main functionalities?

Event Emitting

This feature allows you to emit events and register listeners that get called when those events are emitted.

const EventEmitter2 = require('eventemitter2').EventEmitter2;
const emitter = new EventEmitter2();

emitter.on('event', function() {
  console.log('an event occurred!');
});

emitter.emit('event');

Namespaces/Wildcards

This feature enables the use of namespaces and wildcards for event names, allowing for more flexible event handling.

const EventEmitter2 = require('eventemitter2').EventEmitter2;
const emitter = new EventEmitter2({
  wildcard: true
});

emitter.on('foo.*', function() {
  console.log('foo event occurred!');
});

emitter.emit('foo.bar');

Listening to All Events

This feature allows you to listen to all events that are emitted from an EventEmitter2 instance.

const EventEmitter2 = require('eventemitter2').EventEmitter2;
const emitter = new EventEmitter2();

emitter.onAny(function(event, value) {
  console.log('All event handler:', event, value);
});

emitter.emit('randomEvent', 'with some value');

Other packages similar to eventemitter2

Keywords

FAQs

Package last updated on 20 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc