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

node-pluggable

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

node-pluggable - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

186

lib/pluggable.js

@@ -1,124 +0,92 @@

// Generated by CoffeeScript 1.9.1
(function() {
var EventEmitter, Pluggable, _, async,
slice = [].slice;
var EventEmitter, Pluggable, _, async,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
slice = [].slice;
async = require('async');
async = require('async');
_ = require('lodash');
_ = require('lodash');
EventEmitter = require('events').EventEmitter;
EventEmitter = require('events').EventEmitter;
module.exports = Pluggable = (function() {
function Pluggable() {
this._stack = [];
this._event = new EventEmitter();
}
module.exports = Pluggable = (function(superClass) {
extend(Pluggable, superClass);
Pluggable.prototype._match = function(param) {
return _.filter(this._stack, function(arg) {
var match_param;
match_param = arg[0];
try {
return param.match(match_param);
} catch (_error) {
return false;
}
});
};
function Pluggable() {
this.container = [];
}
Pluggable.prototype.use = function() {
var fn, fns, i, len, match_param;
fns = 1 <= arguments.length ? slice.call(arguments, 0) : [];
match_param = _.first(fns);
if (_.isRegExp(match_param)) {
match_param = fns.shift();
} else if (_.isFunction(match_param)) {
match_param = /.*/;
} else if (_.isString(match_param)) {
try {
match_param = new RegExp(fns.shift(), 'i');
} catch (_error) {
throw new Error('Create regexp failed.');
}
Pluggable.prototype.use = function() {
var fn, fns, i, len, match_param;
fns = 1 <= arguments.length ? slice.call(arguments, 0) : [];
match_param = _.first(fns);
if (_.isRegExp(match_param)) {
match_param = fns.shift();
} else if (_.isFunction(match_param)) {
match_param = /.*/;
} else if (_.isString(match_param)) {
try {
match_param = new RegExp(fns.shift(), 'i');
} catch (_error) {
throw new Error('Create regexp failed.');
}
for (i = 0, len = fns.length; i < len; i++) {
fn = fns[i];
this._stack.push([match_param, fn]);
}
return this;
};
}
for (i = 0, len = fns.length; i < len; i++) {
fn = fns[i];
this.container.push([match_param, fn]);
}
return this;
};
Pluggable.prototype.del = function() {
var fns, match_param, matched_stack;
match_param = arguments[0], fns = 2 <= arguments.length ? slice.call(arguments, 1) : [];
matched_stack = this._match(match_param);
this._stack = _.filter(matched_stack, function(arg) {
var matched_fns, matched_param;
matched_param = arg[0], matched_fns = arg[1];
return !_.some(fns, function(fn) {
return fn.toString() === matched_fns.toString();
});
});
return this;
};
Pluggable.prototype.run = function() {
var callback, i, match_param, params;
match_param = arguments[0], params = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), callback = arguments[i++];
if (!_.isFunction(callback)) {
params = _.union(params, [callback]);
callback = void 0;
}
async.eachSeries(this._match(match_param), (function(_this) {
return function(arg, callback) {
var err, fn, match_param;
match_param = arg[0], fn = arg[1];
Pluggable.prototype.run = function() {
var callback, i, match, match_param, params;
match_param = arguments[0], params = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), callback = arguments[i++];
if (!_.isFunction(callback)) {
params = _.union(params, [callback]);
callback = void 0;
}
match = (function(_this) {
return function(param) {
return _.filter(_this.container, function(arg) {
var match_param;
match_param = arg[0];
try {
return fn.apply(_this, _.union(params, [callback]));
return param.match(match_param);
} catch (_error) {
err = _error;
return callback(err);
return false;
}
};
})(this), (function(_this) {
return function(err) {
if (callback) {
return callback(err);
}
};
})(this));
return this;
};
Pluggable.prototype.on = function() {
var params;
params = 1 <= arguments.length ? slice.call(arguments, 0) : [];
this._event.on.apply(this, params);
return this;
};
Pluggable.prototype.bind = function() {
var fn, fns, i, len, match_param;
match_param = arguments[0], fns = 2 <= arguments.length ? slice.call(arguments, 1) : [];
for (i = 0, len = fns.length; i < len; i++) {
fn = fns[i];
this.on(match_param, fn);
});
};
})(this);
async.eachSeries(match(match_param), (function(_this) {
return function(arg, callback) {
var err, fn, match_param;
match_param = arg[0], fn = arg[1];
try {
return fn.apply(_this, _.union(params, [callback]));
} catch (_error) {
err = _error;
return callback(err);
}
};
})(this), function(err) {
if (callback) {
return callback(err);
}
return this;
};
});
return this;
};
Pluggable.prototype.emit = function() {
var params;
params = 1 <= arguments.length ? slice.call(arguments, 0) : [];
this._event.emit.apply(this, params);
return this;
};
Pluggable.prototype.bind = function() {
var fn, fns, i, len, match_param;
match_param = arguments[0], fns = 2 <= arguments.length ? slice.call(arguments, 1) : [];
for (i = 0, len = fns.length; i < len; i++) {
fn = fns[i];
this.on(match_param, fn);
}
return this;
};
return Pluggable;
return Pluggable;
})();
}).call(this);
//# sourceMappingURL=pluggable.js.map
})(EventEmitter);
{
"name": "node-pluggable",
"version": "0.2.5",
"version": "0.3.0",
"description": "Add your Hook more easily.",

@@ -11,6 +11,3 @@ "main": "./lib/pluggable.js",

"scripts": {
"test": "COV_TEST=true ./node_modules/.bin/mocha --require coffee-coverage/register --compilers coffee:coffee-script/register --require test/support/env --reporter node_modules/mocha-reporter-cov-summary -- test/*.test.coffee",
"test-only": "./node_modules/.bin/mocha --require coffee-coverage/register --compilers coffee:coffee-script/register --require test/support/env -- test/*.test.coffee",
"test-cov-html": "COV_TEST=true ./node_modules/.bin/mocha --require coffee-coverage/register --compilers coffee:coffee-script/register --require test/support/env --reporter html-cov -- test/*.test.coffee > coverage-reporter.html",
"test-coveralls": "COV_TEST=true ./node_modules/.bin/mocha --require coffee-coverage/register --compilers coffee:coffee-script/register --require test/support/env --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js -- test/*.test.coffee"
"test": "./node_modules/.bin/mocha --compilers coffee:coffee-script/register --require test/support/env -- test/*.test.coffee"
},

@@ -25,9 +22,5 @@ "author": "faceair",

"chai": "^2.2.0",
"coffee-coverage": "^0.4.5",
"coffee-script": "^1.9.1",
"mocha": "^2.2.1",
"coveralls": "^2.11.2",
"mocha-lcov-reporter": "0.0.2",
"mocha-reporter-cov-summary": "^0.1.1"
"mocha": "^2.2.1"
}
}

@@ -6,3 +6,2 @@ ## node-pluggable

[![Build Status](https://travis-ci.org/faceair/node-pluggable.svg?branch=master)](https://travis-ci.org/faceair/node-pluggable)
[![Coverage Status](https://coveralls.io/repos/faceair/node-pluggable/badge.svg)](https://coveralls.io/r/faceair/node-pluggable)

@@ -20,7 +19,7 @@ ## Demo

Pluggable = require 'node-pluggable'
pluggable = new Pluggable()
plugin = new Pluggable()
### use([match_param ,] hook_callback...) => this
pluggable.use('article.create', (article, next) ->
plugin.use('article.create', (article, next) ->
article.hook = 'article.create'

@@ -41,3 +40,3 @@ next()

pluggable.run 'article.create', article, ->
plugin.run 'article.create', article, ->
console.log article

@@ -48,14 +47,5 @@

### del([match_param ,] hook_callback...) => this
pluggable.del('article.create', (article, next) ->
article.hook = 'article.create'
next()
)
+ reverse of `use`
### bind(hook_name, hook_callback...) => this
pluggable.bind 'article.update', (article) ->
plugin.bind 'article.update', (article) ->
console.log article

@@ -69,3 +59,3 @@ , (article) ->

pluggable.on 'article.update', (article) ->
plugin.on 'article.update', (article) ->
console.log article

@@ -77,4 +67,4 @@

pluggable.emit 'article.update', 'just a message.'
plugin.emit 'article.update', 'just a message.'
+ emit an event

@@ -84,2 +74,2 @@

[MIT](License)
[MIT](License)
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