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

event-hook

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-hook - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

12

index.js

@@ -83,5 +83,10 @@ var EventEmitter = require('events').EventEmitter;

self.EventHook = function(obj){
var ret = self.EventShim(obj);
var ret;
if(self.IsHooked(obj))
ret = self.GetShim(obj);
else
ret = self.EventShim(obj);
Object.keys(EventEmitter.prototype).forEach(function(funcName){
if(funcName.toLowerCase() == "emit") //Don't hook emit otherwise what the hell are we doing here...
//Don't hook emit otherwise what the hell are we doing here...
if(funcName.toLowerCase() == "emit" || typeof(obj[funcName]) != "function" || obj[funcName].__evtHookMarker)
return;

@@ -95,3 +100,4 @@ obj[funcName] = function(){

return ret[funcName].apply(ret, arguments);
}
};
obj[funcName].__evtHookMarker = true;
});

@@ -98,0 +104,0 @@ obj.__eventHookShim = ret;

{
"name": "event-hook",
"version": "1.0.1",
"version": "1.0.2",
"description": "Allows installation of intermediate procesing functions between an event being emitted on an object and it's listeners receiving the events.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -210,1 +210,38 @@ var evtTools = require('../');

};
exports.testHookAsync = function(test){
test.expect(2);
var testObj = new events.EventEmitter();
var shim = evtTools.EventHook(testObj);
shim.addEventProcessor("testEvent2", function(cb, magicNo){
cb(magicNo + 10);
});
testObj.on("testEvent2", function(magicNo){
test.equal(magicNo, 52, "Incorrect argument was propagated");
test.equal(this, testObj, "Incorrect 'this' context in hook mode")
});
process.nextTick(function(){
testObj.emit("testEvent2",42);
test.done();
});
};
exports.testHookReapply = function(test){
test.expect(2);
var testObj = new events.EventEmitter();
var origOn = testObj.on;
var shim = evtTools.EventHook(testObj);
testObj.on = origOn;
evtTools.EventHook(testObj);
shim.addEventProcessor("testEvent2", function(cb, magicNo){
cb(magicNo + 10);
});
testObj.on("testEvent2", function(magicNo){
test.equal(magicNo, 52, "Incorrect argument was propagated");
test.equal(this, testObj, "Incorrect 'this' context in hook mode")
});
testObj.emit("testEvent2",42);
test.done();
};
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