eventemitter3
Advanced tools
Comparing version 1.0.2 to 1.0.3
64
index.js
'use strict'; | ||
// | ||
// We store our EE objects in a plain object whose properties are event names. | ||
// If `Object.create(null)` is not supported we prefix the event names with a | ||
// `~` to make sure that the built-in object properties are not overridden or | ||
// used as an attack vector. | ||
// We also assume that `Object.create(null)` is available when the event name | ||
// is an ES6 Symbol. | ||
// | ||
var prefix = typeof Object.create !== 'function'; | ||
/** | ||
@@ -43,11 +53,11 @@ * Representation of a single EventEmitter function. | ||
EventEmitter.prototype.listeners = function listeners(event, exists) { | ||
var prefix = typeof event !== 'symbol' ? '~' + event : event | ||
, available = this._events && this._events[prefix]; | ||
var evt = prefix ? '~'+ event : event | ||
, available = this._events && this._events[evt]; | ||
if (exists) return !!available; | ||
if (!available) return []; | ||
if (this._events[prefix].fn) return [this._events[prefix].fn]; | ||
if (this._events[evt].fn) return [this._events[evt].fn]; | ||
for (var i = 0, l = this._events[prefix].length, ee = new Array(l); i < l; i++) { | ||
ee[i] = this._events[prefix][i].fn; | ||
for (var i = 0, l = this._events[evt].length, ee = new Array(l); i < l; i++) { | ||
ee[i] = this._events[evt][i].fn; | ||
} | ||
@@ -66,7 +76,7 @@ | ||
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { | ||
var prefix = typeof event !== 'symbol' ? '~' + event : event; | ||
var evt = prefix ? '~'+ event : event; | ||
if (!this._events || !this._events[prefix]) return false; | ||
if (!this._events || !this._events[evt]) return false; | ||
var listeners = this._events[prefix] | ||
var listeners = this._events[evt] | ||
, len = arguments.length | ||
@@ -127,10 +137,10 @@ , args | ||
var listener = new EE(fn, context || this) | ||
, prefix = typeof event !== 'symbol' ? '~' + event : event; | ||
, evt = prefix ? '~'+ event : event; | ||
if (!this._events) this._events = {}; | ||
if (!this._events[prefix]) this._events[prefix] = listener; | ||
if (!this._events) this._events = prefix ? {} : Object.create(null); | ||
if (!this._events[evt]) this._events[evt] = listener; | ||
else { | ||
if (!this._events[prefix].fn) this._events[prefix].push(listener); | ||
else this._events[prefix] = [ | ||
this._events[prefix], listener | ||
if (!this._events[evt].fn) this._events[evt].push(listener); | ||
else this._events[evt] = [ | ||
this._events[evt], listener | ||
]; | ||
@@ -152,10 +162,10 @@ } | ||
var listener = new EE(fn, context || this, true) | ||
, prefix = typeof event !== 'symbol' ? '~' + event : event; | ||
, evt = prefix ? '~'+ event : event; | ||
if (!this._events) this._events = {}; | ||
if (!this._events[prefix]) this._events[prefix] = listener; | ||
if (!this._events) this._events = prefix ? {} : Object.create(null); | ||
if (!this._events[evt]) this._events[evt] = listener; | ||
else { | ||
if (!this._events[prefix].fn) this._events[prefix].push(listener); | ||
else this._events[prefix] = [ | ||
this._events[prefix], listener | ||
if (!this._events[evt].fn) this._events[evt].push(listener); | ||
else this._events[evt] = [ | ||
this._events[evt], listener | ||
]; | ||
@@ -177,7 +187,7 @@ } | ||
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { | ||
var prefix = typeof event !== 'symbol' ? '~' + event : event; | ||
var evt = prefix ? '~'+ event : event; | ||
if (!this._events || !this._events[prefix]) return this; | ||
if (!this._events || !this._events[evt]) return this; | ||
var listeners = this._events[prefix] | ||
var listeners = this._events[evt] | ||
, events = []; | ||
@@ -211,5 +221,5 @@ | ||
if (events.length) { | ||
this._events[prefix] = events.length === 1 ? events[0] : events; | ||
this._events[evt] = events.length === 1 ? events[0] : events; | ||
} else { | ||
delete this._events[prefix]; | ||
delete this._events[evt]; | ||
} | ||
@@ -229,4 +239,4 @@ | ||
if (event) delete this._events[typeof event !== 'symbol' ? '~' + event : event]; | ||
else this._events = {}; | ||
if (event) delete this._events[prefix ? '~'+ event : event]; | ||
else this._events = prefix ? {} : Object.create(null); | ||
@@ -233,0 +243,0 @@ return this; |
{ | ||
"name": "eventemitter3", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "EventEmitter3 focuses on performance while maintaining a Node.js AND browser compatible interface.", | ||
@@ -8,2 +8,3 @@ "main": "index.js", | ||
"test": "mocha test.js", | ||
"sync": "node versions.js", | ||
"coverage": "istanbul cover ./node_modules/.bin/_mocha -- test.js", | ||
@@ -38,2 +39,3 @@ "test-travis": "istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js" | ||
}, | ||
"pre-commit": "sync, test", | ||
"devDependencies": { | ||
@@ -40,0 +42,0 @@ "assume": "1.2.x", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
218
11799
1