Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
ev-emitter
Advanced tools
The ev-emitter package is a simple event emitter library for JavaScript. It allows you to add event-driven architecture to your applications by providing methods to emit events and listen for them.
Add Event Listener
This feature allows you to add an event listener for a specific event. In the code sample, an event listener is added for the 'event' event, and when the event is emitted, the callback function `onEvent` is executed.
const EvEmitter = require('ev-emitter');
const emitter = new EvEmitter();
function onEvent() {
console.log('Event triggered!');
}
emitter.on('event', onEvent);
emitter.emitEvent('event');
Remove Event Listener
This feature allows you to remove an event listener for a specific event. In the code sample, the event listener for the 'event' event is removed before the event is emitted, so the callback function `onEvent` is not executed.
const EvEmitter = require('ev-emitter');
const emitter = new EvEmitter();
function onEvent() {
console.log('Event triggered!');
}
emitter.on('event', onEvent);
emitter.off('event', onEvent);
emitter.emitEvent('event');
Emit Event
This feature allows you to emit an event, triggering all the listeners that are registered for that event. In the code sample, the 'event' event is emitted, and the callback function `onEvent` is executed.
const EvEmitter = require('ev-emitter');
const emitter = new EvEmitter();
function onEvent() {
console.log('Event triggered!');
}
emitter.on('event', onEvent);
emitter.emitEvent('event');
The 'events' package is the built-in Node.js event emitter module. It provides a similar event-driven architecture and is widely used in Node.js applications. Compared to ev-emitter, 'events' is more feature-rich and is part of the Node.js core modules.
The 'eventemitter3' package is a high-performance event emitter for both Node.js and the browser. It offers a similar API to ev-emitter but is optimized for performance and has a smaller footprint. It is a good alternative if you need a lightweight and fast event emitter.
The 'mitt' package is a tiny functional event emitter. It provides a minimalistic API for event handling and is suitable for use in both Node.js and browser environments. Compared to ev-emitter, 'mitt' is even more lightweight and has a simpler API.
Lil' event emitter — add a little pub/sub
EvEmitter adds publish/subscribe pattern to a browser class. It's a smaller version of Olical/EventEmitter. That EventEmitter is full featured, widely used, and great. This EvEmitter has just the base event functionality to power the event API in libraries like Isotope, Flickity, Masonry, and imagesLoaded.
// Inherit prototype, IE8+
MyClass.prototype = new EvEmitter();
// Inherit prototype, IE9+
MyClass.prototype = Object.create( EvEmitter.prototype );
// Mixin prototype
_.extend( MyClass.prototype, EvEmitter.prototype );
// single instance
var emitter = new EventEmitter();
Add an event listener.
emitter.on( eventName, listener )
eventName
- String - name of the eventlistener
- FunctionRemove an event listener.
emitter.off( eventName, listener )
Add an event listener to be triggered only once.
emitter.once( eventName, listener )
Trigger an event.
emitter.emitEvent( eventName, args )
eventName
- String - name of the eventargs
- Array - arguments passed to listeners// create event emitter
var emitter = new EventEmitter();
// listeners
function hey( a, b, c ) {
console.log( 'Hey', a, b, c )
}
function ho( a, b, c ) {
console.log( 'Ho', a, b, c )
}
function letsGo( a, b, c ) {
console.log( 'Lets go', a, b, c )
}
// bind listeners
emitter.on( 'rock', hey )
emitter.once( 'rock', ho )
// trigger letsGo once
emitter.on( 'rock', letsGo )
// emit event
emitter.emitEvent( 'rock', [ 1, 2, 3 ] )
// => 'Hey', 1, 2, 3
// => 'Ho', 1, 2, 3
// => 'Lets go', 1, 2, 3
// unbind
emitter.off( 'rock', ho )
emitter.emitEvent( 'rock', [ 4, 5, 6 ] )
// => 'Hey' 4, 5, 6
EvEmitter is released under the MIT License. Have at it.
FAQs
lil' event emitter
We found that ev-emitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.