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

emittery

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emittery - npm Package Compare versions

Comparing version 0.12.0 to 0.12.1

53

index.js

@@ -13,15 +13,9 @@ 'use strict';

// Define a symbol that allows internal code to emit meta events, but prevents userland from doing so.
const metaEventsAllowed = Symbol('metaEventsAllowed');
let canEmitMetaEvents = false;
let isGlobalDebugEnabled = false;
function assertEventName(eventName, allowMetaEvents) {
function assertEventName(eventName) {
if (typeof eventName !== 'string' && typeof eventName !== 'symbol' && typeof eventName !== 'number') {
throw new TypeError('`eventName` must be a string, symbol, or number');
}
if (isMetaEvent(eventName) && allowMetaEvents !== metaEventsAllowed) {
throw new TypeError('`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`');
}
}

@@ -161,2 +155,13 @@

function emitMetaEvent(emitter, eventName, eventData) {
if (isMetaEvent(eventName)) {
try {
canEmitMetaEvents = true;
emitter.emit(eventName, eventData);
} finally {
canEmitMetaEvents = false;
}
}
}
class Emittery {

@@ -258,3 +263,3 @@ static mixin(emitteryPropertyName, methodNames) {

for (const eventName of eventNames) {
assertEventName(eventName, metaEventsAllowed);
assertEventName(eventName);
getListeners(this, eventName).add(listener);

@@ -265,3 +270,3 @@

if (!isMetaEvent(eventName)) {
this.emit(listenerAdded, {eventName, listener}, metaEventsAllowed);
emitMetaEvent(this, listenerAdded, {eventName, listener});
}

@@ -278,3 +283,3 @@ }

for (const eventName of eventNames) {
assertEventName(eventName, metaEventsAllowed);
assertEventName(eventName);
getListeners(this, eventName).delete(listener);

@@ -285,3 +290,3 @@

if (!isMetaEvent(eventName)) {
this.emit(listenerRemoved, {eventName, listener}, metaEventsAllowed);
emitMetaEvent(this, listenerRemoved, {eventName, listener});
}

@@ -308,3 +313,3 @@ }

for (const eventName of eventNames) {
assertEventName(eventName, metaEventsAllowed);
assertEventName(eventName);
}

@@ -315,5 +320,9 @@

async emit(eventName, eventData, allowMetaEvents) {
assertEventName(eventName, allowMetaEvents);
async emit(eventName, eventData) {
assertEventName(eventName);
if (isMetaEvent(eventName) && !canEmitMetaEvents) {
throw new TypeError('`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`');
}
this.logIfDebugEnabled('emit', eventName, eventData);

@@ -343,5 +352,9 @@

async emitSerial(eventName, eventData, allowMetaEvents) {
assertEventName(eventName, allowMetaEvents);
async emitSerial(eventName, eventData) {
assertEventName(eventName);
if (isMetaEvent(eventName) && !canEmitMetaEvents) {
throw new TypeError('`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`');
}
this.logIfDebugEnabled('emitSerial', eventName, eventData);

@@ -376,3 +389,3 @@

anyMap.get(this).add(listener);
this.emit(listenerAdded, {listener}, metaEventsAllowed);
emitMetaEvent(this, listenerAdded, {listener});
return this.offAny.bind(this, listener);

@@ -390,3 +403,3 @@ }

this.emit(listenerRemoved, {listener}, metaEventsAllowed);
emitMetaEvent(this, listenerRemoved, {listener});
anyMap.get(this).delete(listener);

@@ -441,3 +454,3 @@ }

if (typeof eventName !== 'undefined') {
assertEventName(eventName, metaEventsAllowed);
assertEventName(eventName);
}

@@ -444,0 +457,0 @@

{
"name": "emittery",
"version": "0.12.0",
"version": "0.12.1",
"description": "Simple and modern async event emitter",

@@ -5,0 +5,0 @@ "license": "MIT",

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