Socket
Socket
Sign inDemoInstall

eventemitter2

Package Overview
Dependencies
0
Maintainers
2
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.13 to 0.4.14

32

lib/eventemitter2.js

@@ -1,2 +0,9 @@

;!function(exports, undefined) {
/*!
* EventEmitter2
* https://github.com/hij1nx/EventEmitter2
*
* Copyright (c) 2013 hij1nx
* Licensed under the MIT license.
*/
;!function(undefined) {

@@ -334,6 +341,6 @@ var isArray = Array.isArray ? Array.isArray : function _isArray(obj) {

}
return (listeners.length > 0) || this._all;
return (listeners.length > 0) || !!this._all;
}
else {
return this._all;
return !!this._all;
}

@@ -401,2 +408,6 @@

if (typeof fn !== 'function') {
throw new Error('onAny only accepts instances of Function');
}
if(!this._all) {

@@ -406,6 +417,2 @@ this._all = [];

if (typeof fn !== 'function') {
throw new Error('onAny only accepts instances of Function');
}
// Add the function to the event listener collection.

@@ -557,9 +564,14 @@ this._all.push(fn);

if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(function() {
return EventEmitter;
});
} else {
} else if (typeof exports === 'object') {
// CommonJS
exports.EventEmitter2 = EventEmitter;
}
}(typeof process !== 'undefined' && typeof process.title !== 'undefined' && typeof exports !== 'undefined' ? exports : window);
else {
// Browser global.
window.EventEmitter2 = EventEmitter;
}
}();
{
"name": "eventemitter2",
"version": "0.4.13",
"version": "0.4.14",
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.",

@@ -5,0 +5,0 @@ "keywords": ["event", "events", "emitter", "eventemitter"],

@@ -1,7 +0,10 @@

# EventEmitter2
[![build-status](https://www.codeship.io/projects/3ad58940-4c7d-0131-15d5-5a8cd3f550f8/status)](https://www.codeship.io/projects/11259)
# SYNOPSIS
EventEmitter2 is an implementation of the EventEmitter found in Node.js
## Features
# DESCRIPTION
### FEATURES
- Namespaces/Wildcards.

@@ -20,3 +23,3 @@ - Times To Listen (TTL), extends the `once` concept with `many`.

## Differences (Non breaking, compatible with existing EventEmitter)
### Differences (Non breaking, compatible with existing EventEmitter)

@@ -28,6 +31,22 @@ - The constructor takes a configuration object.

var server = new EventEmitter2({
wildcard: true, // should the event emitter use wildcards.
delimiter: '::', // the delimiter used to segment namespaces, defaults to `.`.
newListener: false, // if you want to emit the newListener event set to true.
maxListeners: 20, // the max number of listeners that can be assigned to an event, defaults to 10.
//
// use wildcards.
//
wildcard: true,
//
// the delimiter used to segment namespaces, defaults to `.`.
//
delimiter: '::',
//
// if you want to emit the newListener event set to true.
//
newListener: false,
//
// max listeners that can be assigned to an event, default 10.
//
maxListeners: 20
});

@@ -61,3 +80,3 @@ ```

## API
# API

@@ -74,13 +93,13 @@ When an `EventEmitter` instance experiences an error, the typical action is

**Namespaces** with **Wildcards**
To use namespaces/wildcards, pass the `wildcard` option into the EventEmitter constructor.
When namespaces/wildcards are enabled, events can either be strings (`foo.bar`) separated
by a delimiter or arrays (`['foo', 'bar']`). The delimiter is also configurable as a
constructor option.
To use namespaces/wildcards, pass the `wildcard` option into the EventEmitter
constructor. When namespaces/wildcards are enabled, events can either be
strings (`foo.bar`) separated by a delimiter or arrays (`['foo', 'bar']`). The
delimiter is also configurable as a constructor option.
An event name passed to any event emitter method can contain a wild card (the `*` character).
If the event name is a string, a wildcard may appear as `foo.*`. If the event name is an array,
the wildcard may appear as `['foo', '*']`.
An event name passed to any event emitter method can contain a wild card (the
`*` character). If the event name is a string, a wildcard may appear as `foo.*`.
If the event name is an array, the wildcard may appear as `['foo', '*']`.
If either of the above described events were passed to the `on` method, subsequent emits such
as the following would be observed...
If either of the above described events were passed to the `on` method,
subsequent emits such as the following would be observed...

@@ -93,4 +112,4 @@ ```javascript

#### emitter.addListener(event, listener)
#### emitter.on(event, listener)
### emitter.addListener(event, listener)
### emitter.on(event, listener)

@@ -100,3 +119,3 @@ Adds a listener to the end of the listeners array for the specified event.

```javascript
server.on('data', function(value1, value2, value3 /* accepts any number of expected values... */) {
server.on('data', function(value1, value2, value3, ...) {
console.log('The event was raised!');

@@ -112,3 +131,3 @@ });

#### emitter.onAny(listener)
### emitter.onAny(listener)

@@ -123,3 +142,3 @@ Adds a listener that will be fired when any event is emitted.

#### emitter.offAny(listener)
### emitter.offAny(listener)

@@ -136,3 +155,4 @@ Removes the listener that will be fired when any event is emitted.

Adds a **one time** listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.
Adds a **one time** listener for the event. The listener is invoked
only the first time the event is fired, after which it is removed.

@@ -145,5 +165,7 @@ ```javascript

#### emitter.many(event, timesToListen, listener)
### emitter.many(event, timesToListen, listener)
Adds a listener that will execute **n times** for the event before being removed. The listener is invoked only the first time the event is fired, after which it is removed.
Adds a listener that will execute **n times** for the event before being
removed. The listener is invoked only the first **n times** the event is
fired, after which it is removed.

@@ -157,6 +179,7 @@ ```javascript

#### emitter.removeListener(event, listener)
#### emitter.off(event, listener)
### emitter.removeListener(event, listener)
### emitter.off(event, listener)
Remove a listener from the listener array for the specified event. **Caution**: changes array indices in the listener array behind the listener.
Remove a listener from the listener array for the specified event.
**Caution**: changes array indices in the listener array behind the listener.

@@ -173,3 +196,3 @@ ```javascript

#### emitter.removeAllListeners([event])
### emitter.removeAllListeners([event])

@@ -179,10 +202,14 @@ Removes all listeners, or those of the specified event.

#### emitter.setMaxListeners(n)
### emitter.setMaxListeners(n)
By default EventEmitters will print a warning if more than 10 listeners are added to it. This is a useful default which helps finding memory leaks. Obviously not all Emitters should be limited to 10. This function allows that to be increased. Set to zero for unlimited.
By default EventEmitters will print a warning if more than 10 listeners
are added to it. This is a useful default which helps finding memory leaks.
Obviously not all Emitters should be limited to 10. This function allows
that to be increased. Set to zero for unlimited.
#### emitter.listeners(event)
### emitter.listeners(event)
Returns an array of listeners for the specified event. This array can be manipulated, e.g. to remove listeners.
Returns an array of listeners for the specified event. This array can be
manipulated, e.g. to remove listeners.

@@ -193,8 +220,9 @@ ```javascript

});
console.log(console.log(server.listeners('get')); // [ [Function] ]
console.log(server.listeners('get')); // [ [Function] ]
```
#### emitter.listenersAny()
### emitter.listenersAny()
Returns an array of listeners that are listening for any event that is specified. This array can be manipulated, e.g. to remove listeners.
Returns an array of listeners that are listening for any event that is
specified. This array can be manipulated, e.g. to remove listeners.

@@ -205,15 +233,12 @@ ```javascript

});
console.log(console.log(server.listenersAny()[0]); // [ [Function] ] // someone connected!
console.log(server.listenersAny()[0]); // [ [Function] ]
```
#### emitter.emit(event, [arg1], [arg2], [...])
### emitter.emit(event, [arg1], [arg2], [...])
Execute each of the listeners that may be listening for the specified event name in order with the list of arguments.
Execute each of the listeners that may be listening for the specified event
name in order with the list of arguments.
## Test coverage
# LICENSE
There is a test suite that tries to cover each use case, it can be found <a href="https://github.com/hij1nx/EventEmitter2/tree/master/test">here</a>.
## Licence
(The MIT License)

@@ -223,6 +248,17 @@

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc