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

glob-events

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-events - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

17

CHANGES.md
# Changes
## v0.2.0
## 0.3.0
- Added 'on'
- Added 'removeAllListeners'
- Support event object with options to disable `matchers` and `listeners`
- Changed `listeners` options to use the same flags as the event object
- Added `once`
- Emitting 'newListener' in `addListener`, `on` and `once`
- Emitting 'removeListener' in `removeListener` and `removeAllListeners`
- Bugfixes
## v0.1.0
## 0.2.0
- Added `on`
- Added `removeAllListeners`
## 0.1.0
- Initial release

@@ -14,3 +14,20 @@ /*

var E_EVENT = 'Event must be string';
var EVENT_ADD = {
event : 'newListener',
matchers : false
};
var EVENT_REMOVE = {
event : 'removeListener',
matchers : false
};
function options(opts) {
return opts ? {
matchers : opts.matchers === undefined ? true : opts.matchers,
onlyMatchers : opts.listeners === undefined ? false : !opts.listeners
} : null;
}
function Emitter() {

@@ -23,6 +40,11 @@ this._store = new Store();

emit: function (event) {
var opts;
if (typeof event === 'object') {
opts = options(event);
event = event.event;
}
if (typeof event !== 'string') {
throw new TypeError(E_EVENT);
}
var i = this._store.iterator(event), fn, l = arguments.length, a, j;
var i = this._store.iterator(event, opts), fn, l = arguments.length, a, j;
if (l > 1) {

@@ -47,5 +69,19 @@ a = [];

}
this.emit(EVENT_ADD, name, fn._once || fn);
this._store.add(name, fn);
},
once: function (name, fn) {
if (typeof fn !== 'function') {
throw new TypeError(E_LISTENER);
}
var s = this._store;
var f = function () {
s.remove(name, f);
fn.apply(null, arguments);
};
f._once = fn;
this.addListener(name, f);
},
removeListener: function (name, fn) {

@@ -55,2 +91,10 @@ if (typeof fn !== 'function') {

}
var i = this._store.iterator(name), f;
while ((f = i.next()) !== undefined) {
if (f._once === fn) {
fn = f;
break;
}
}
this.emit(EVENT_REMOVE, name, fn);
this._store.remove(name, fn);

@@ -60,2 +104,6 @@ },

removeAllListeners: function (name) {
var i = this._store.iterator(name), f;
while ((f = i.next()) !== undefined) {
this.emit(EVENT_REMOVE, i.name, f._once || f);
}
this._store.removeAll(name);

@@ -65,3 +113,11 @@ },

listeners: function (name, opts) {
return this._store.iterator(name, opts).toArray();
if (typeof name === 'object') {
opts = name;
name = '**';
}
var i = this._store.iterator(name, options(opts)), f, a = [];
while ((f = i.next()) !== undefined) {
a.push(typeof f._once === 'function' ? f._once : f);
}
return a;
}

@@ -68,0 +124,0 @@

{
"name" : "glob-events",
"version" : "0.2.0",
"version" : "0.3.0",
"description" : "Event emitter with glob support on event names",

@@ -10,9 +10,9 @@ "keywords" : ["event", "emitter", "glob", "listener"],

"engines" : {
"node" : ">=0.8"
"node" : ">=0.10"
},
"scripts" : {
"start" : "mocha --watch -R min",
"lint" : "jslint --color -- ./**/*.js",
"test-wd" : "mochify --wd -R dot",
"test" : "npm run lint && mocha -R dot && mochify -R dot"
"start" : "mochify --watch --node --cover",
"lint" : "jslint --color './**/*.js'",
"test-wd" : "mochify --wd",
"test" : "npm run lint && mocha -R spec && mochify --cover"
},

@@ -24,10 +24,8 @@ "repository" : {

"dependencies" : {
"glob-store" : "~0.1.0"
"glob-store" : "~0.2.0"
},
"devDependencies" : {
"mocha" : ">=1.17 <2",
"jslint" : "~0.2.7",
"browserify" : ">=3.19 <4",
"coverify" : "~1.0.6",
"mochify" : "~0.3.1",
"jslint" : "~0.3.1",
"mochify" : "~0.7.0",
"bench" : "~0.3.5"

@@ -34,0 +32,0 @@ },

@@ -39,2 +39,4 @@ # glob-events.js [![Build Status](https://travis-ci.org/mantoni/glob-events.js.png?branch=master)](http://travis-ci.org/mantoni/glob-events.js)

- `addListener(event, fn)` / `on(event, fn)`: Registers a listener for an event
- `once(event, fn)`: Registers a listener for an event that is automatically
removed on the first invokation
- `removeListener(event, fn)`: Unregisteres a listener for an event

@@ -45,12 +47,25 @@ - `removeAllListeners([event])`: Unregisters all listeners, or all listeners

for the given event. Matching rules are applied on the event name as
described in the [glob-tree match expressions][]. The options are passed on
to the [glob-tree iterarator][].
described in the [glob-tree match expressions][].
### Options
The `options` argument can have these properties:
- `matchers`: Emit to matchers, defaults to `true`
- `listeners`: Emit to listeners, defaults to `true`
The first argument passed to `emit` can be an object with an `event` property
and any of the above options.
### Events
- `newListener`: Emitted by `addListener`, `on` and `once` with the event name
and the new listener function. Matchers will not receive this event.
- `removeListener`: Emitted by `removeListener` and `removeAllListeners` with
the event name and the removed listener function. Matchers will not receive
this event.
## TODO
- once(event, fn)
- setMaxListeners(n)
- listenerCount()
- emit newListener events
- emit removeListener events

@@ -62,2 +77,1 @@ ## License

[glob-tree match expressions]: https://github.com/mantoni/glob-tree.js#match-expressions
[glob-tree iterator]: https://github.com/mantoni/glob-tree.js#node-api
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