Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
uEvent is a event emitter library which provides the observer pattern to javascript objects. It works on node.js and browser and also supports RequireJS (AMD).
It is a fork of jeromeetienne/microevents.js with the changes of few other forks and custom changes.
on
, off
, once
, trigger
)$ npm install uevent
Direct
import { EventEmitter } from 'uevent';
const obj = new EventEmitter();
Class extend
class Manager extends EventEmitter {
}
class obj = new Manager();
Mixin
import { mixin as eventEmitterMixin } from 'uevent';
const obj = {};
eventEmitterMixin(obj);
on
Add one or many event handlers.
// bind 'callback' to 'event'
obj.on('event', callback);
// bind 'callback' to 'event1' and 'event2'
obj.on('event1 event2', callback);
// bind 'callback1' to 'event1' and 'callback2' to 'event2'
obj.on({
event1: callback1,
event2: callback2
});
off
Remove one or many or all event handlers.
// remove all callbacks for 'event'
obj.off('event');
// remove 'callback' if attached to 'event'
obj.off('event', callback);
// remove all callbacks for 'event1' and 'event2'
obj.off('event1 event2');
// remove 'callback1' if attached to 'event1' and 'callback2' if attached to 'event2'
obj.off({
event1: callback1,
event2: callback2
});
// remove all callbacks
obj.off();
once
Same as on
but the callbacks will be removed after the first invocation.
The callbacks attached once are only called by trigger
and not by change
.
The first parameter of the callback is always an Event
object having the following properties :
type
the name of the eventtarget
the source object of the eventargs
additional parametersWhen additional parameters are provided they are passed to the callback :
const callback = function(event, param1, param2) {};
When using the handleEvent
feature you only get the event object :
const listener = {
handleEvent: function(event) {}
};
trigger
Trigger all handlers for an event. Accept optional arguments transmitted to the callbacks.
// trigger 'event'
obj.trigger('event');
// trigger 'event' with arguments
obj.trigger('event', true, 42);
change
Works like trigger
but returns a value. This is used to filter a value before display for example. All callbacks must accept at least on input value and return the modified (or not) value.
// call 'event' filters with 'Hello world' input
var newVal = obj.change('event', 'Hello world')
// call 'event' filters with 'Hello world' input and other arguments
var newVal = obj.change('event', 'Hello world', true, 42)
The Event
object has an additional value
property which holds the current value.
Call preventDefault()
on this Event
object to "mark" the event. After calling trigger
you get a reference to this Event
object and can test isDefaultPrevented()
.
obj.on('event', function(e, id) {
if (id == 0) {
e.preventDefault();
}
});
const e = obj.trigger('event', id);
if (!e.isDefaultPrevented()) {
// ...
}
Call stopPropagation()
on the Event
object to prevent any further callbacks to be called. Works for trigger
and change
.
obj.on('event', function(e, val) {
e.stopPropagation();
return val;
});
obj.on('event', function(e, val) {
return 'azerty';
});
const newVal = obj.change('event', '1234');
// newVal is still '1234'
This library is available under the MIT license.
FAQs
Event emitter micro library
The npm package uevent receives a total of 1,495 weekly downloads. As such, uevent popularity was classified as popular.
We found that uevent 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.