{"_id":"events-intercept","_rev":"16-d30e79d1ef143b2098f354922ed614b8","name":"events-intercept","description":"event interceptors - like middleware for EventEmitter","dist-tags":{"latest":"2.0.0"},"versions":{"0.1.0":{"name":"events-intercept","version":"0.1.0","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"mocha test"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","dependencies":{"async":"^0.9.0","lodash":"^2.4.1"},"devDependencies":{"chai":"^1.9.1","chai-spies":"^0.5.1","gulp":"^3.8.2","mocha":"^1.20.1"},"gitHead":"c6a44d082fdc15074c6c4381c3cf60203ebe51c8","_id":"events-intercept@0.1.0","_shasum":"1d9a61739e7f825a357e543c7201eaf658d03b23","_from":".","_npmVersion":"1.4.15","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"1d9a61739e7f825a357e543c7201eaf658d03b23","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-0.1.0.tgz","integrity":"sha512-7vkPPELuoPMuuichLpFDsp4ufdXJSHE1+UKqBgffPDF4ZiSmCSQeLOpPKwj5YdddQM3WDl2Yri1lVG2LAOdoqg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEfbSx/QF6Ntbt5+t1DSbGcz2ThBJ4xbFV/aK6tKXccqAiBnvuJcTKVxP83mTZMm2NPSzXKOeTMZC/XCaCQYpBskrQ=="}]}},"0.2.0":{"name":"events-intercept","version":"0.2.0","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"node_modules/mocha/bin/mocha test","posttest":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec","coverage":"cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","dependencies":{"async":"^0.9.0","istanbul":"^0.2.12","lodash":"^2.4.1"},"devDependencies":{"chai":"^1.9.1","chai-spies":"^0.5.1","coveralls":"^2.10.1","gulp":"^3.8.2","istanbul":"^0.2.12","mocha":"^1.20.1"},"gitHead":"0bccdcfdf302c895376e37e0ad6a485f4b7dc226","_id":"events-intercept@0.2.0","_shasum":"aadf798cadbd6474d5888b0caeedfe3f00b68092","_from":".","_npmVersion":"1.4.15","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"aadf798cadbd6474d5888b0caeedfe3f00b68092","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-0.2.0.tgz","integrity":"sha512-07zh5Ss4Tkd2TPcduwKtRYhjffWEgmHn3ysuih5myjM4I7djfViy2AkXVTNC94IV4Pm/yx2A1wJungi1t2GEFw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICog6jnw20CnIa4ulHNOUIJcdh/LoDnpggvVhSjCE1C0AiEAoJDsErOCPGDZ0dKa+Xr0lQKnqm35SEw+jVayzLzxTM4="}]}},"0.2.1":{"name":"events-intercept","version":"0.2.1","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"node_modules/mocha/bin/mocha test","posttest":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec","coverage":"cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","dependencies":{"async":"^0.9.0","lodash":"^2.4.1"},"devDependencies":{"chai":"^1.9.1","chai-spies":"^0.5.1","coveralls":"^2.10.1","gulp":"^3.8.2","istanbul":"^0.2.12","mocha":"^1.20.1"},"gitHead":"943be089a623d4ae9a541d3b19b3647e34275692","_id":"events-intercept@0.2.1","_shasum":"1bc8d6f340e8360cf7193c0881553a2a2ef29d9c","_from":".","_npmVersion":"1.4.15","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"1bc8d6f340e8360cf7193c0881553a2a2ef29d9c","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-0.2.1.tgz","integrity":"sha512-h05KswM+PyG539ZRD4PHKSubsGmpEcAoq6FhFQyzBBXzYaKOKIQ06LCiimc8NRAUz/JemJd6GJZPOIZ/TAnhNg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC+MFFJxQ5FvTCgYXqFwTDxmWwN5rFahKhS+/CQDIf16gIhAOv1oqX5bkMyDSV5PPgRRopUoVyDH1CnMFxYLbUev74M"}]}},"1.0.0":{"name":"events-intercept","version":"1.0.0","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"node_modules/mocha/bin/mocha test","posttest":"istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec","coveralls":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","dependencies":{"lodash":"^2.4.1"},"devDependencies":{"chai":"^1.9.1","chai-spies":"^0.5.1","coveralls":"^2.10.1","gulp":"^3.8.2","istanbul":"^0.2.12","mocha":"^1.20.1","sinon":"^1.10.2","sinon-chai":"^2.5.0"},"gitHead":"42cc29c6aefc826a481cf7f9795f4823a8f6f527","_id":"events-intercept@1.0.0","_shasum":"ca85b1664f15814670ebe70c1cf6b65355611905","_from":".","_npmVersion":"1.4.16","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"ca85b1664f15814670ebe70c1cf6b65355611905","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-1.0.0.tgz","integrity":"sha512-dDT3SkkZ/YS7zFGbxvDtPU8/hJ7WyXeRogZSPSOCKlK0W8C9Bqn3RFcybjEnYNoZrWmvDsJqQDsBsqPA7RcIgg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCjQ5tXTEg0AexFuQiygA3sVyqnpwshqdwyELk2D2MYLwIhAOH64XkvEsPdPOunBOctyN1LK2EQeP0vG+/5HOSd5+j1"}]}},"1.1.0":{"name":"events-intercept","version":"1.1.0","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"node_modules/mocha/bin/mocha test","posttest":"istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec","coveralls":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","dependencies":{"lodash":"^2.4.1"},"devDependencies":{"chai":"^1.9.1","chai-spies":"^0.5.1","coveralls":"^2.10.1","gulp":"^3.8.2","istanbul":"^0.2.12","mocha":"^1.20.1","sinon":"^1.10.2","sinon-chai":"^2.5.0"},"gitHead":"5ecad77438c1fc0c6986afc10e658690a23aa4c3","_id":"events-intercept@1.1.0","_shasum":"7b3a10d62c84178cf0a58ba61d1ceff9e14a6a0f","_from":".","_npmVersion":"1.4.16","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"7b3a10d62c84178cf0a58ba61d1ceff9e14a6a0f","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-1.1.0.tgz","integrity":"sha512-3aJkKpewcPQB2TKbtTzkyxhdOX1gddKm48QuzCV9KTXl4fNEFDyPR2SYLnSHxnwppWDHKqeuRtgl1p/Oj5/UJw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD0NYVCelj7qpDY765KgzXL9526EODdxGhQoI0LWgHAEgIgUQyccmr4BrtJ3cUBELu62VfqtVAKTC2mWQ1zWkxV4Gw="}]}},"1.1.1":{"name":"events-intercept","version":"1.1.1","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"node_modules/mocha/bin/mocha test","posttest":"istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec","coveralls":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","devDependencies":{"chai":"^1.9.1","chai-spies":"^0.5.1","coveralls":"^2.10.1","gulp":"^3.8.2","istanbul":"^0.2.12","mocha":"^1.20.1","sinon":"^1.10.2","sinon-chai":"^2.5.0"},"gitHead":"a61505bf00f4d17a8dd1e7a27c42076a9df798b5","_id":"events-intercept@1.1.1","_shasum":"e20d3c37fc1f56f2e3a278588e015d9c3ca8897b","_from":".","_npmVersion":"1.4.23","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"e20d3c37fc1f56f2e3a278588e015d9c3ca8897b","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-1.1.1.tgz","integrity":"sha512-z6hqWIKslpHPMMNl9XHmPIvbiuqOjKMUI4EYoFHB/m44Lj6daPFlm5+jeCBAl3AA8vV0s1jcPjD33kcDA25uGw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDOthmqinTX1wQRDineF+/tT7RCBQ5Qe6hcF/95S5Tl9AiEA6nK01RHPAHaEsVHp2pxXxr/9ppR77tiQ9kT8p4KEShg="}]}},"2.0.0":{"name":"events-intercept","version":"2.0.0","description":"event interceptors - like middleware for EventEmitter","main":"lib/events-intercept.js","scripts":{"test":"mocha test","posttest":"istanbul cover _mocha -- -R spec","coveralls":"istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"},"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"author":{"name":"@brandonhorst"},"license":"MIT","bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"homepage":"https://github.com/brandonhorst/events-intercept","devDependencies":{"chai":"^1.10.0","coveralls":"^2.11.2","istanbul":"^0.3.5","mocha":"^2.1.0","sinon":"^1.12.2","sinon-chai":"^2.6.0"},"gitHead":"9e83c2d178c267980c2e58ef0c7e930c2cd55043","_id":"events-intercept@2.0.0","_shasum":"adbf38681c5a4b2011c41ee41f61a34cba448897","_from":".","_npmVersion":"2.1.11","_nodeVersion":"0.10.33","_npmUser":{"name":"brandonhorst","email":"brandonhorst@gmail.com"},"maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"dist":{"shasum":"adbf38681c5a4b2011c41ee41f61a34cba448897","tarball":"https://registry.npmjs.org/events-intercept/-/events-intercept-2.0.0.tgz","integrity":"sha512-blk1va0zol9QOrdZt0rFXo5KMkNPVSp92Eju/Qz8THwKWKRKeE0T8Br/1aW6+Edkyq9xHYgYxn2QtOnUKPUp+Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH5MF5UvlOEWOvCEXSbBePoGUHC5UPSufE2luKuss1CKAiEAtWS2k8gUbteqpbO3XPDI0RxnKh33d64PlQlGSxCkMbw="}]}}},"readme":"#`events-intercept`\n\n[![Build Status](https://travis-ci.org/brandonhorst/events-intercept.svg?branch=master)](https://travis-ci.org/brandonhorst/events-intercept)\n[![Coverage Status](https://coveralls.io/repos/brandonhorst/events-intercept/badge.png?branch=master)](https://coveralls.io/r/brandonhorst/events-intercept?branch=master)\n\nThe node [EventEmitter](http://nodejs.org/api/events.html) is very powerful. However, at times it could be valuable to intercept events before they reach their handlers, to modify the data, or emit other events. That's a job for `event-intercept`.\n\n##Installation\n\n```sh\nnpm install events-intercept\n```\n\n##Standalone Usage\n\nThe module contains a constructor, `EventEmitter`, which inherits from the standard node `events.EventEmitter`.\n\n\tvar EventEmitter = require('events-intercept').EventEmitter;\n\tvar emitter = new EventEmitter();\n\nIn our application, we have an object that will emit a `data` event, and pass it a single argument.\n\n\temitter.emit('data', 'myData')\n\nIt is very easy to listen for this event and handle it\n\n\temitter.on('data', function(arg) {\n\t\tconsole.log(arg);\n\t}); //logs 'myData'\n\nHowever, we want to intercept that event and modify the data. We can do that by setting an `interceptor` with `intercept(event, interceptor)`. It is passed all arguments that would be passed to the emitter, as well as a standard node callback. In this case, let's just add a prefix on to the data.\n\n\temitter.intercept('data', function(arg, done) {\n\t\treturn done(null, 'intercepted ' + arg);\n\t});\n\nThis code will be executed before the handler, and the new argument will be passed on to the handler appropriately.\n\n\temitter.emit('data', 'some other data');\n\t//logs 'intercepted some other data'\n\nIf multiple interceptors are added to a single event, they will be called in the order that they are added, like [async.waterfall](https://github.com/caolan/async#waterfall).\n\nHere's that sample code all together. Of course, `intercept` supports proper function chaining.\n\n\tvar eventsIntercept = require('events-intercept');\n\tvar emitter = new eventsIntercept.EventEmitter();\n\n\temitter\n\t.on('data', function(arg) {\n\t\tconsole.log(arg);\n\t}).intercept('data', function(arg, done) {\n\t\treturn done(null, 'intercepted ' + arg);\n\t}).emit('data', 'myData');\n\t//logs 'intercepted myData'\n\nPlease see `test/intercept.js` for more complete samples.\n\n##Calling Separate Events\n\nThere may be times when you want to intercept one event and call another. Luckily, all `intercept` handlers are called with the `EventEmitter` as the `this` context, so you can `emit` events yourself.\n\n\temitter.intercept('data', function(done) {\n\t\tthis\n\t\t.emit('otherData')\n\t\t.emit('thirdData');\n\t\treturn done(null);\n\t});\n\t//emits 'data', 'otherData', and 'thirdData'\n\nRemember, `emit`ting an event that you are `intercept`ing will cause a loop, so be careful.\n\nIn fact, an `intercept`or do not need to call the callback at all, which means that the event that was `intercept`ed will never be called at all.\n\n\n\temitter.intercept('data', function(done) {\n\t\tthis\n\t\t.emit('otherData')\n\t\t.emit('thirdData');\n\t});\n\t//emits 'otherData' and 'thirdData' but not 'data'\n\n##Utilities\n\n`events-intercept` supports all of the useful utilities that the standard `EventEmitter` supports:\n\n* `interceptors(type)` returns an array of all interceptors (functions) for the given type.\n* `removeInterceptor(type, interceptor)` removes an interceptor of a given type. You must pass in the interceptor function.\n* `removeAllInterceptors(type)` removes all interceptors for a given type.\n* `removeAllInterceptors()` removes all interceptors. Will remove the `removeInterceptor` event last, so they will all get triggered.\n* the EventEmitter will throw a warning if more than 10 interceptors are added to a single event, as this could represent a memory leak. `setMaxInterceptors(n)` allows you to change that. Set it to 0 for no limit.\n\nAll of these are demonstrated in the tests.\n\n##Patching\n\nOf course, many EventEmitters that you have the pleasure of using will not have the foresight to use `event-intercept`. Thankfully, Javascript is awesome, it's possible to monkey patch the interception capabilities onto an existing object. Just call\n\n\tvar events = require('events');\n\tvar eventsIntercept = require('events-intercept');\n\n\tvar emitter = new events.EventEmitter();\n\n\teventsIntercept.patch(emitter)\n\n\temitter\n\t.on('data', function(arg) {\n\t\tconsole.log(arg);\n\t}).intercept('data', function(arg, done) {\n\t\treturn done(null, 'intercepted ' + arg);\n\t}).emit('data', 'myData');\n\t//logs 'intercepted myData'\n\nNow, you should be able to call `intercept` on the standard `EventEmitter`.\n\nThis is also shown in `test/intercept.js`.\n","maintainers":[{"name":"brandonhorst","email":"brandonhorst@gmail.com"}],"time":{"modified":"2022-06-17T21:36:04.761Z","created":"2014-06-25T20:36:48.122Z","0.1.0":"2014-06-25T20:36:48.122Z","0.2.0":"2014-06-26T15:29:41.798Z","0.2.1":"2014-06-26T16:24:39.509Z","1.0.0":"2014-06-27T10:06:26.679Z","1.1.0":"2014-06-27T10:08:50.777Z","1.1.1":"2014-09-15T01:41:47.720Z","2.0.0":"2015-01-02T22:17:20.152Z"},"homepage":"https://github.com/brandonhorst/events-intercept","keywords":["event","events","emit","intercept","tap","hook","report","mutate","EventEmitter"],"repository":{"type":"git","url":"https://github.com/brandonhorst/events-intercept.git"},"author":{"name":"@brandonhorst"},"bugs":{"url":"https://github.com/brandonhorst/events-intercept/issues"},"license":"MIT","readmeFilename":"README.md"}