node-pluggable
Advanced tools
Comparing version 0.1.3 to 0.1.4
161
index.js
// Generated by CoffeeScript 1.9.1 | ||
(function() { | ||
var EventEmitter, _, async, | ||
var EventEmitter, Pluggable, _, async, | ||
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
slice = [].slice; | ||
@@ -12,81 +13,103 @@ | ||
exports.match = function(param) { | ||
return _.filter(this.stack, function(arg) { | ||
var match_param; | ||
match_param = arg[0]; | ||
return param.match(match_param); | ||
}); | ||
}; | ||
Pluggable = (function() { | ||
function Pluggable() { | ||
this.bind = bind(this.bind, this); | ||
this.run = bind(this.run, this); | ||
this.del = bind(this.del, this); | ||
this.use = bind(this.use, this); | ||
this.match = bind(this.match, this); | ||
this.stack = []; | ||
this.event = new EventEmitter(); | ||
} | ||
exports.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.match = function(param) { | ||
return _.filter(this.stack, function(arg) { | ||
var match_param; | ||
match_param = arg[0]; | ||
return param.match(match_param); | ||
}); | ||
}; | ||
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.stack.push([match_param, fn]); | ||
} | ||
return this; | ||
}; | ||
exports.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(); | ||
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; | ||
}; | ||
return this; | ||
}; | ||
exports.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++]; | ||
return async.eachSeries(this.match(match_param), function(arg, callback) { | ||
var fn, match_param; | ||
match_param = arg[0], fn = arg[1]; | ||
return fn.apply(this, _.union(params, [callback])); | ||
}, function(err) { | ||
if (callback) { | ||
return callback(err); | ||
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++]; | ||
return async.eachSeries(this.match(match_param), function(arg, callback) { | ||
var fn, match_param; | ||
match_param = arg[0], fn = arg[1]; | ||
return fn.apply(this, _.union(params, [callback])); | ||
}, function(err) { | ||
if (callback) { | ||
return callback(err); | ||
} | ||
}); | ||
}; | ||
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); | ||
} | ||
}); | ||
}; | ||
return this; | ||
}; | ||
exports.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; | ||
}; | ||
Pluggable.prototype.emit = function() { | ||
var params; | ||
params = 1 <= arguments.length ? slice.call(arguments, 0) : []; | ||
this.event.emit.apply(this, params); | ||
return this; | ||
}; | ||
module.exports = function(stack) { | ||
if (stack == null) { | ||
stack = []; | ||
} | ||
return _.extend(new EventEmitter(), _.extend(exports, { | ||
stack: stack | ||
})); | ||
}; | ||
return Pluggable; | ||
})(); | ||
module.exports = Pluggable; | ||
}).call(this); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "node-pluggable", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Add your Hook more easily.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -13,3 +13,4 @@ ## node-pluggable | ||
pluggable = require('node-pluggable')() | ||
Pluggable = require 'node-pluggable' | ||
pluggable = new Pluggable() | ||
@@ -16,0 +17,0 @@ pluggable.use('article.create', (article, next) -> |
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
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
5836
98
53