{"_id":"@carlegbert/emitter-test","_rev":"1-ef0c72e9b720b7ed77af557a9b532949","name":"@carlegbert/emitter-test","dist-tags":{"latest":"1.3.2"},"versions":{"1.3.2":{"name":"@carlegbert/emitter-test","private":false,"version":"1.3.2","description":"Simple Emitter base class.","main":"Emitter.js","engines":{"node":">= 6.0.0"},"scripts":{"lint":"eslint **/*.js","prepublishOnly":"./prepublish","test":"ava","test:cov":"nyc ava","test:watch":"ava --watch"},"repository":{"type":"git","url":"git+https://github.com/carlegbert/emitter.git"},"author":{"name":"Carl Egbert","email":"egbertcarl@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/carlegbert/emitter/issues"},"homepage":"https://github.com/carlegbert/emitter#readme","devDependencies":{"ava":"^0.25.0","eslint":"^4.19.1","eslint-config-airbnb-base":"^13.0.0","eslint-plugin-import":"^2.13.0","nyc":"^12.0.2"},"ava":{"files":["test/*.spec.js"]},"_resolved":"","_integrity":"","_from":"file:carlegbert-emitter-test-1.3.2.tgz","_id":"@carlegbert/emitter-test@1.3.2","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"carlegbert","email":"egbertcarl@gmail.com"},"dist":{"integrity":"sha512-jdOUhQdq+/XkrAlwF/q/HkHc+Rx2Krl6oPHvjsAJKd3NuWbnzj9FRuSNp11DFQhRsc6phcAwExw8gkmmye/Ksw==","shasum":"61b542b4f4d38a1b36489a6da78d8ee25e419329","tarball":"https://registry.npmjs.org/@carlegbert/emitter-test/-/emitter-test-1.3.2.tgz","fileCount":8,"unpackedSize":232198,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcN9naCRA9TVsSAnZWagAAp84P/AotDxhjhCDzH5ETwitR\nDQhw5FMNQW/jNywZR2d5g+5zn8WIGbyM0L2qBNp1/WlRnZj5yGgwebQ9r+ep\n3Ji/onDIhVj/FYT3Rn4ukdAJTDGpotYaV1+nGPsQ4FGsoVUPJZrSxj4sucKj\nKtwQ/AJk5RcmOqaVGEaKiZDxSql8mmKTmp31ARV6Gc4eGWOycpHQ3bvKr7Fa\nrZ9obTYdWWohZmMFg8gnSZNUn04hBRAM50Tqa6CPxSjqvPSJurs2lkhpqwG+\nQxNhP3icZizatAFJ/VcDlra8ey957tXy0upV7utNCFMAXxbyrH2d8fjyDL1Z\nHELif/5PhFCZpGBXZ77HckbO+28XeKnHbhZS75jJhWzyhOTI/lp+szRKrT6b\ngoxQmyQ9uR2HSRzz3i5qVkYfS2LUbhyxBprkLusFc/ZgvkdbOXHyMaYikFjn\ncl0ZllB6AYu43XR/bb8HMnH4VV7hxSfhZzaTvf5zt3PVrRFvfPZTXvVURRNF\nLDE2En0OJeSJ9s8tBUWD0tHb//cL6QRiKSEmMOtZbqm0z+HRbxEhGeyR44lP\nedXKiobHrAtlUxOfG5mC0kPGsiscL57wufz4XG6bca7JlgqsfwqK5AyopEL0\nOTWVEi60OJaWOQAWmwLu3vhKMdLX4Oq4FzFLSoiu8GeWtG/7itysjtWe3u4i\nqL/A\r\n=GjVc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC8RxzUTqG56gxc2IvrvmmgneeOra3l0ARQo9xbNhCMYQIhALMH9Zoro9r/OqQUre0wyCkAFl9m0LN6b7hnUfUailG/"}]},"maintainers":[{"name":"carlegbert","email":"egbertcarl@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/emitter-test_1.3.2_1547164122267_0.10297965365776562"},"_hasShrinkwrap":false}},"time":{"created":"2019-01-10T23:48:42.088Z","1.3.2":"2019-01-10T23:48:42.356Z","modified":"2022-04-04T21:57:40.820Z"},"maintainers":[{"name":"carlegbert","email":"egbertcarl@gmail.com"}],"description":"Simple Emitter base class.","homepage":"https://github.com/carlegbert/emitter#readme","repository":{"type":"git","url":"git+https://github.com/carlegbert/emitter.git"},"author":{"name":"Carl Egbert","email":"egbertcarl@gmail.com"},"bugs":{"url":"https://github.com/carlegbert/emitter/issues"},"license":"MIT","readme":"# Emitter\n\nThis is a simple JavaScript event emitter. It can run in node versions 6.0.0 or higher.\n\n## Installation\n\n```sh\n$ npm install @carlegbert/emitter\n```\n\n## Useage\n\nThis module exposes an `Emitter` class. This class can be used to create instances directly:\n\n```js\nconst Emitter = require('@carlegbert/emitter');\n\nemitter = new Emitter();\n\n```\n\nor subclassed:\n\n```js\nclass FancyEmitter extends Emitter {\n  ...\n}\n\nconst fancyEmitter = new FancyEmitter();\n```\n\nAn event handler can be registered at a name with `on`:\n\n```js\nconst eventHandler = console.log('myEventName happened!');\nemitter.on('myEventName', eventHandler);\n```\n\nor with 'once', if you would like to register an event that will happen at most one time.\n\n```js\nemitter.once('myEventName', () => console.log('myEventName happened! this function only gets called once.'));\n```\n\nYou can call the registered event handlers by calling `emit`. If there are multiple handlers at an event name, they will be called in the order that they were registered.\n\n```js\nemitter.emit('myEventName');\n// 'myEventName happened!'\n// 'myEventName happened! this function only gets called once.'\n```\n\nWhen you `emit`, you may also supply any number of arguments, which will be passed to all of the emitted functions.\n\n```js\nemitter.on('eventWithArgs', x => console.log(x));\nemitter.emit('eventWithArgs', 'I was passed to emit');\n// 'I was passed to emit'\n```\n\nYou can remove an event handler by passing the name of the event and a reference to the registered function to `remove`.\n\n```js\nemitter.remove('myEventName', eventHandler);\n```\n\nYou can also remove all event handlers registered at a specific name with 'removeAll'. If want to unregister all event handlers period, you can call `removeAll` without passing it an event name.\n\n```js\n// Removes all events at eventName\nemitter.removeAll('myEventName');\n// Removes all events at any name\nemitter.removeAll();\n```\n\n### A note about scope\n\nEvent handlers will be called with the scope of the Emitter object. If you want your listener to be bound to a different scope, you can use `Function.prototype.bind` to bind your event handler to the scope that you desire, or better yet, use an arrow function.\n\n## API\n\n### `constructor()`\n\nTakes no arguments. Will return an instance of the Emitter class.\n\n### `emit(eventName: String|number, ...args: any)`\n\nTakes an eventName, which ideally should be a string or a number, and any number of additional arguments. Will call all of the event handlers registered at `eventName` and pass them `...args`, in the order they were registered. If any registered handlers throw an error, a new error will be thrown after all registered events have been called.\n\n### `on(eventName: String|number, fn: function)`\n\nWill register `fn` for event `eventName`, to be emitted by `emit`.\n\n### `once(eventName: String|number, fn: function)`\n\nWill register `fn` for event `eventName`, to be emitted by `emit`. Will be unregistered after it has been called once.\n\n### `remove(eventName: String|number, fn: function)`\n\nWill unregister `fn` for event `eventName`, where `fn` is a reference to a function registered at `eventName`. Once unregistered, a handler will no longer be emitted. If there are no events at `eventName`, or if `fn` is not a handler for `eventName`, nothing will happen. If the same listener is registered for an event multiple times, only the first instance will be removed.\n\n### `removeAll(eventName: String|number)`\n\nWill unregister all events at `eventName`. **If `eventName` is not supplied, ALL events at ALL names will be unregistered.**\n\n### `listeners(eventName: String|number)`\n\nGets all listeners registered at `eventName` (or any empty array if there are none). Will return an array of objects, each with a `fn` property (the event handler) and a boolean `once` property indicating whether or not the event is a one-time handler.\n","readmeFilename":"README.md"}