Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
The 'yaeti' npm package is a lightweight library that provides a simple implementation of the EventTarget interface, which is a part of the DOM specification. This package is useful for creating custom event-driven architectures in JavaScript applications.
EventTarget Implementation
This feature allows you to create an instance of EventTarget, add event listeners, and dispatch events. It mimics the behavior of the EventTarget interface found in the DOM, making it useful for custom event handling in non-DOM environments.
const yaeti = require('yaeti');
// Create an instance of EventTarget
const eventTarget = new yaeti.EventTarget();
// Define an event listener
function eventListener(event) {
console.log('Event received:', event.type);
}
// Add the event listener
eventTarget.addEventListener('customEvent', eventListener);
// Dispatch an event
const event = new yaeti.Event('customEvent');
eventTarget.dispatchEvent(event);
Custom Event Creation
This feature allows you to create custom events with additional properties. The 'detail' property can be used to pass extra information with the event, similar to the CustomEvent interface in the DOM.
const yaeti = require('yaeti');
// Create a custom event with additional properties
const customEvent = new yaeti.Event('customEvent', {
detail: { key: 'value' }
});
// Access the custom properties
console.log(customEvent.detail); // Output: { key: 'value' }
EventEmitter3 is a high-performance event emitter for Node.js and the browser. It provides a similar event-driven architecture but is more focused on performance and flexibility. Unlike yaeti, it does not aim to mimic the DOM EventTarget interface.
Mitt is a tiny (~200 bytes) functional event emitter. It provides a simple and minimalistic API for event handling. While it does not mimic the DOM EventTarget interface like yaeti, it is extremely lightweight and easy to use.
Event-target-shim is a polyfill for the EventTarget interface. It provides a more complete and spec-compliant implementation of EventTarget, making it a closer alternative to yaeti for those who need full compliance with the DOM specification.
Yet Another EventTarget Implementation.
The library exposes both the EventTarget interface and the Event interface.
$ npm install yaeti --save
var yaeti = require('yaeti');
// Custom class we want to make an EventTarget.
function Foo() {
// Call EventTarget constructor
yaeti.EventTarget.call(this);
}
// Inherit EventTarget prototype
Foo.prototype = Object.create(yaeti.EventTarget.prototype);
Foo.prototype.constructor = Foo;
// Create an instance.
var foo = new Foo();
function listener1() {
console.log('listener1');
}
function listener2() {
console.log('listener2');
}
foo.addEventListener('bar', listener1);
foo.addEventListener('bar', listener2);
foo.removeEventListener('bar', listener1);
var event = new yaeti.Event('bar');
foo.dispatchEvent(event);
// Output:
// => "listener2"
yaeti.EventTarget
interfaceImplementation of the EventTarget interface.
function Foo() {
yaeti.EventTarget.call(this);
}
Foo.prototype = Object.create(yaeti.EventTarget.prototype);
Foo.prototype.constructor = Foo;
class Foo extends EventTarget () {
constructor () {
super();
}
}
The interface implements the addEventListener
, removeEventListener
and dispatchEvent
methods as defined by the W3C.
listeners
read-only propertyReturns an object whose keys are configured event types (String) and whose values are an array of listeners (functions) for those event types.
yaeti.Event
interfaceImplementation of the Event interface.
NOTE: Just useful in Node (the browser already exposes the native Event
interface).
var event = new yaeti.Event('bar');
FAQs
Yet Another EventTarget Implementation
The npm package yaeti receives a total of 705,779 weekly downloads. As such, yaeti popularity was classified as popular.
We found that yaeti 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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.