{"_id":"emits","_rev":"200560","name":"emits","description":"returns a function which will emit and parse the specified event","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"time":{"modified":"2021-06-03T12:31:42.000Z","created":"2013-11-14T08:26:44.839Z","3.0.0":"2015-01-03T16:23:30.486Z","2.0.0":"2014-12-29T13:26:56.024Z","1.0.2":"2014-12-28T13:02:50.548Z","1.0.1":"2014-10-06T16:07:08.898Z","1.0.0":"2014-10-06T07:18:59.783Z","0.0.1":"2014-01-03T22:11:29.796Z","0.0.0":"2013-11-14T08:26:44.839Z"},"users":{"dandrewgarvin":true},"author":{"name":"Arnout Kazemier"},"repository":{"type":"git","url":"https://github.com/primus/emits"},"versions":{"3.0.0":{"name":"emits","version":"3.0.0","description":"returns a function which will emit and parse the specified event","main":"index.js","scripts":{"test":"mocha test.js","coverage":"istanbul cover node_modules/.bin/_mocha -- test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"},"repository":{"type":"git","url":"https://github.com/primus/emits"},"keywords":["emits","event","parser","eventemitter"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/primus/emits/issues"},"homepage":"https://github.com/primus/emits","devDependencies":{"assume":"0.0.x","istanbul":"0.3.x","mocha":"2.1.x","pre-commit":"0.0.x"},"gitHead":"c8ff8940633cf45ed1b99fd380b742f64b3311e0","_id":"emits@3.0.0","_shasum":"32752bba95e1707b219562384ab9bb8b1fd62f70","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"V1","email":"info@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"dist":{"shasum":"32752bba95e1707b219562384ab9bb8b1fd62f70","size":2866,"noattachment":false,"key":"/emits/-/emits-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-3.0.0.tgz"},"directories":{},"publish_time":1420302210486,"_cnpm_publish_time":1420302210486,"_hasShrinkwrap":false},"2.0.0":{"name":"emits","version":"2.0.0","description":"returns a function which will emit and parse the specified event","main":"index.js","scripts":{"test":"mocha test.js","coverage":"istanbul cover node_modules/.bin/_mocha -- test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"},"repository":{"type":"git","url":"https://github.com/primus/emits"},"keywords":["emits","event","parser","eventemitter"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/primus/emits/issues"},"homepage":"https://github.com/primus/emits","devDependencies":{"assume":"0.0.x","istanbul":"0.3.x","mocha":"2.1.x","pre-commit":"0.0.x"},"gitHead":"b322726c29554ae92c9603fd037253b61a6fdb60","_id":"emits@2.0.0","_shasum":"c2ac2429a151abf149d85a22b8d1e698aee8c311","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"V1","email":"info@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"dist":{"shasum":"c2ac2429a151abf149d85a22b8d1e698aee8c311","size":3016,"noattachment":false,"key":"/emits/-/emits-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-2.0.0.tgz"},"directories":{},"publish_time":1419859616024,"_cnpm_publish_time":1419859616024,"_hasShrinkwrap":false},"1.0.2":{"name":"emits","version":"1.0.2","description":"returns a function which will emit and parse the specified event","main":"index.js","scripts":{"test":"mocha test.js","coverage":"istanbul cover node_modules/.bin/_mocha -- test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- test.js"},"repository":{"type":"git","url":"https://github.com/primus/emits"},"keywords":["emits","event","parser","eventemitter"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/primus/emits/issues"},"homepage":"https://github.com/primus/emits","devDependencies":{"assume":"0.0.x","istanbul":"0.3.x","mocha":"2.1.x","pre-commit":"0.0.x"},"gitHead":"f416174a1a349461a8817cd07d3874f7f486d500","_id":"emits@1.0.2","_shasum":"db20ec6668325071c313441e30cfe2a69ea73859","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"V1","email":"info@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"dist":{"shasum":"db20ec6668325071c313441e30cfe2a69ea73859","size":2605,"noattachment":false,"key":"/emits/-/emits-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-1.0.2.tgz"},"directories":{},"publish_time":1419771770548,"_cnpm_publish_time":1419771770548,"_hasShrinkwrap":false},"1.0.1":{"name":"emits","version":"1.0.1","description":"returns a function which will emit and parse the specified event","main":"index.js","scripts":{"test":"mocha --reporter spec --ui bdd test.js","coverage":"istanbul cover node_modules/.bin/_mocha -- --reporter spec --ui bdd test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --ui bdd test.js"},"repository":{"type":"git","url":"https://github.com/primus/emits"},"keywords":["emits","event","parser","eventemitter"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/primus/emits/issues"},"homepage":"https://github.com/primus/emits","devDependencies":{"assume":"0.0.x","istanbul":"0.3.x","mocha":"1.21.x","pre-commit":"0.0.x"},"gitHead":"4df43a4c00d342ca7f4dbf26a2301fd4bdfba493","_id":"emits@1.0.1","_shasum":"cf8e1ab65a436f4b06ef6dca375b2abaef408a2c","_from":".","_npmVersion":"1.4.27","_npmUser":{"name":"V1","email":"info@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"dist":{"shasum":"cf8e1ab65a436f4b06ef6dca375b2abaef408a2c","size":3245,"noattachment":false,"key":"/emits/-/emits-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-1.0.1.tgz"},"directories":{},"publish_time":1412611628898,"_cnpm_publish_time":1412611628898,"_hasShrinkwrap":false},"1.0.0":{"name":"emits","version":"1.0.0","description":"returns a function which will emit and parse the specified event","main":"index.js","scripts":{"test":"mocha --reporter spec --ui bdd test.js","coverage":"istanbul cover node_modules/.bin/_mocha -- --reporter spec --ui bdd test.js","test-travis":"istanbul cover node_modules/.bin/_mocha --report lcovonly -- --reporter spec --ui bdd test.js"},"repository":{"type":"git","url":"https://github.com/primus/emits"},"keywords":["emits","event","parser","eventemitter"],"author":{"name":"Arnout Kazemier"},"license":"MIT","bugs":{"url":"https://github.com/primus/emits/issues"},"homepage":"https://github.com/primus/emits","devDependencies":{"assume":"0.0.x","istanbul":"0.3.x","mocha":"1.21.x","pre-commit":"0.0.x"},"gitHead":"96c7735d9eb78a11d79421ba17129d7297aba7b6","_id":"emits@1.0.0","_shasum":"18d500c9b4eb400399366a759429442dd4b7cf1c","_from":".","_npmVersion":"1.4.27","_npmUser":{"name":"V1","email":"info@3rd-Eden.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"dist":{"shasum":"18d500c9b4eb400399366a759429442dd4b7cf1c","size":3237,"noattachment":false,"key":"/emits/-/emits-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-1.0.0.tgz"},"directories":{},"publish_time":1412579939783,"_cnpm_publish_time":1412579939783,"_hasShrinkwrap":false},"0.0.1":{"name":"emits","description":"Simple cross-platform event emitter.","version":"0.0.1","homepage":"https://github.com/ryanve/emits","license":"MIT","author":{"name":"Ryan Van Etten"},"keywords":["events","emitter","emit","simple","ender","server","browser"],"main":"./emits.js","ender":"noop","repository":{"type":"git","url":"https://github.com/ryanve/emits.git"},"devDependencies":{"aok":"~1.7.0","grunt":"~0.4.1","grunt-contrib-uglify":"~0.2.4","grunt-contrib-concat":"~0.3.0","grunt-contrib-jshint":"~0.6.4"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/ryanve/emits/issues"},"_id":"emits@0.0.1","dist":{"shasum":"51807da071ee28dafe6257e6d0801995d81c6f8c","size":5131,"noattachment":false,"key":"/emits/-/emits-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-0.0.1.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"ryanve","email":"ryanve@gmail.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"directories":{},"publish_time":1388787089796,"_cnpm_publish_time":1388787089796,"_hasShrinkwrap":false},"0.0.0":{"name":"emits","description":"Simple event emitter.","version":"0.0.0","homepage":"https://github.com/ryanve/emits","license":"MIT","author":{"name":"Ryan Van Etten"},"keywords":["events","emitter","emit","simple","ender","server","browser"],"main":"./emits.js","ender":"noop","repository":{"type":"git","url":"https://github.com/ryanve/emits.git"},"devDependencies":{"aok":"~1.7.0","grunt":"~0.4.1","grunt-contrib-uglify":"~0.2.4","grunt-contrib-concat":"~0.3.0","grunt-contrib-jshint":"~0.6.4"},"readmeFilename":"README.md","bugs":{"url":"https://github.com/ryanve/emits/issues"},"_id":"emits@0.0.0","dist":{"shasum":"01d71762ebfd5b00ca1de4ceda603d92ea278905","size":5136,"noattachment":false,"key":"/emits/-/emits-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/emits/download/emits-0.0.0.tgz"},"_from":".","_npmVersion":"1.3.11","_npmUser":{"name":"ryanve","email":"ryanve@gmail.com"},"maintainers":[{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"lpinca","email":"luigipinca@gmail.com"},{"name":"v1","email":"info@3rd-Eden.com"}],"directories":{},"publish_time":1384417604839,"_cnpm_publish_time":1384417604839,"_hasShrinkwrap":false}},"readme":"# emits\n\n[![Version npm][version]](http://browsenpm.org/package/emits)[![Build Status][build]](https://travis-ci.org/primus/emits)[![Dependencies][david]](https://david-dm.org/primus/emits)[![Coverage Status][cover]](https://coveralls.io/r/primus/emits?branch=master)[![IRC channel][irc]](https://webchat.freenode.net/?channels=primus)\n\n[version]: https://img.shields.io/npm/v/emits.svg?style=flat-square\n[build]: https://img.shields.io/travis/primus/emits/master.svg?style=flat-square\n[david]: https://img.shields.io/david/primus/emits.svg?style=flat-square\n[cover]: https://img.shields.io/coveralls/primus/emits/master.svg?style=flat-square\n[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23primus-00a8ff.svg?style=flat-square\n\n## Installation\n\nThis module is compatible with browserify and node.js and is therefore released\nthrough npm:\n\n```\nnpm install --save emits\n```\n\n## Usage\n\nIn all examples we assume that you've assigned the `emits` function to the\nprototype of your class. This class should inherit from an `EventEmitter` class\nwhich uses the `emit` function to emit events. For example:\n\n```js\n'use strict';\n\nvar EventEmitter = require('events').EventEmitter\n  , emits = require('emits');\n\nfunction Example() {\n  EventEmitter.call(this);\n}\n\nrequire('util').inherits(Example, EventEmitter);\n\n//\n// You can directly assign the function to the prototype if you wish or store it\n// in a variable and then assign it to the prototype. What pleases you more.\n//\nExample.prototype.emits = emits; // require('emits');\n\n//\n// Also initialize the example so we can use the assigned method.\n//\nvar example = new Example();\n```\n\nNow that we've set up our example code we can finally demonstrate the beauty of\nthis functionality. To create a function that emits `data` we can simply do:\n\n```js\nvar data = example.emits('data');\n```\n\nEvery time you invoke the `data()` function it will emit the `data` event with\nall the arguments you supplied. If you want to \"curry\" some extra arguments you\ncan add those after the event name:\n\n```js\nvar data = example.emits('data', 'foo');\n```\n\nNow when you call `data()` the `data` event will receive `foo` as first argument\nand the rest of the arguments would be the ones that you've supplied to the\n`data()` function.\n\nIf you supply a function as the last argument we assume that this is an async\nargument parser. This allows you to modify the arguments, prevent the event from\nbeing fired or just clear all supplied arguments (except for the ones that are\ncurried in). The first argument of the function is always the callback function,\nall other arguments after that are the ones emitted with the event. The callback\nfunction follows the usual error first pattern. When the callback is invoked\nwith an error it will emit an `error` event on the `EventEmitter` instance. In\nour case the `example` instance:\n\n```js\nvar data = example.emits('data', function parser(next, arg) {\n  try { arg = JSON.parse(arg); }\n  catch (e) { return next(e); }\n\n  next(undefined, arg);\n});\n```\n\nTo modify the data you need to supply the change as second argument:\n\n```js\nvar data = example.emits('data', function parser(next, arg) {\n  next(undefined, 'bar');\n});\n```\n\nIn the example above we've transformed the incoming argument to `bar`. So when\nyou call `data()` it will emit a `data` event with `bar` as the second argument.\nIf you call the callback with `undefined` as second argument we assume that no\nmodifications have been made and we emit all received arguments. If you want to\nclear all received arguments, call the callback with `null`:\n\n```js\nvar data = example.emits('data', function parser(next, arg) {\n  next(undefined, null);\n});\n```\n\n### Patterns\n\nIn Primus the most common pattern for this module is to proxy events from one\ninstance to another:\n\n```js\neventemitter.on('data', example.emits('data'));\n```\n\nIt is also very useful to re-format data. For example, in the case of WebSockets,\nif we don't want to reference `evt.data` every time we need to access the data,\nwe can parse the argument as following:\n\n```js\nvar ws = new WebSocket('wss://example.org/path');\nws.onmessage = example.emits('data', function parser(next, evt) {\n  next(undefined, evt.data);\n});\n```\n\nIn the example above we will now emit the `data` event with a direct reference\nto `evt.data`. The following final example shows how you can prevent events\nfrom being emitted.\n\n```js\nvar ws = new WebSocket('wss://example.org/path');\nws.onmessage = example.emits('data', function parser(next, evt) {\n  var data;\n\n  try { data = JSON.parse(evt.data); }\n  catch (e) { return next(e); }\n\n  if ('object' !== typeof data || Array.isArray(data)) return;\n\n  next(undefined, data);\n});\n```\n\nBy not calling the callback we make sure that the event is not emitted. So the\n`data` event will only be fired if we've received a valid JSON document from the\nserver and it's an object.\n\n## License\n\nMIT\n","_attachments":{},"homepage":"https://github.com/primus/emits","bugs":{"url":"https://github.com/primus/emits/issues"},"license":"MIT"}