{
  "manifest": {
    "name": "emittery",
    "version": "0.10.2",
    "description": "Simple and modern async event emitter",
    "license": "MIT",
    "repository": {
      "type": "git",
      "url": "https://github.com/sindresorhus/emittery.git"
    },
    "funding": "https://github.com/sindresorhus/emittery?sponsor=1",
    "author": {
      "name": "Sindre Sorhus",
      "email": "sindresorhus@gmail.com",
      "url": "https://sindresorhus.com"
    },
    "engines": {
      "node": ">=12"
    },
    "scripts": {
      "test": "xo && nyc ava && tsd"
    },
    "files": [
      "index.js",
      "index.d.ts"
    ],
    "keywords": [
      "event",
      "emitter",
      "eventemitter",
      "events",
      "async",
      "emit",
      "on",
      "once",
      "off",
      "listener",
      "subscribe",
      "unsubscribe",
      "pubsub",
      "tiny",
      "addlistener",
      "addeventlistener",
      "dispatch",
      "dispatcher",
      "observer",
      "trigger",
      "await",
      "promise",
      "typescript",
      "ts",
      "typed"
    ],
    "devDependencies": {
      "@types/node": "^15.6.1",
      "ava": "^2.4.0",
      "delay": "^4.3.0",
      "nyc": "^15.0.0",
      "p-event": "^4.1.0",
      "tsd": "^0.19.1",
      "xo": "^0.39.0"
    },
    "nyc": {
      "reporter": [
        "html",
        "lcov",
        "text"
      ]
    },
    "_registry": "npm",
    "_loc": "/homez.1033/heliovt/.cache/yarn/v6/npm-emittery-0.10.2-902eec8aedb8c41938c46e9385e9db7e03182933-integrity/node_modules/emittery/package.json",
    "readmeFilename": "readme.md",
    "readme": "# <img src=\"media/header.png\" width=\"1000\">\n\n> Simple and modern async event emitter\n\n[![Coverage Status](https://codecov.io/gh/sindresorhus/emittery/branch/main/graph/badge.svg)](https://codecov.io/gh/sindresorhus/emittery)\n[![](https://badgen.net/bundlephobia/minzip/emittery)](https://bundlephobia.com/result?p=emittery)\n\nIt works in Node.js and the browser (using a bundler).\n\nEmitting events asynchronously is important for production code where you want the least amount of synchronous operations. Since JavaScript is single-threaded, no other code can run while doing synchronous operations. For Node.js, that means it will block other requests, defeating the strength of the platform, which is scalability through async. In the browser, a synchronous operation could potentially cause lags and block user interaction.\n\n## Install\n\n```\n$ npm install emittery\n```\n\n## Usage\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\n\nemitter.on('🦄', data => {\n\tconsole.log(data);\n});\n\nconst myUnicorn = Symbol('🦄');\n\nemitter.on(myUnicorn, data => {\n\tconsole.log(`Unicorns love ${data}`);\n});\n\nemitter.emit('🦄', '🌈'); // Will trigger printing '🌈'\nemitter.emit(myUnicorn, '🦋');  // Will trigger printing 'Unicorns love 🦋'\n```\n\n## API\n\n### eventName\n\nEmittery accepts strings and symbols as event names.\n\nSymbol event names can be used to avoid name collisions when your classes are extended, especially for internal events.\n\n### isDebugEnabled\n\nToggle debug mode for all instances.\n\nDefault: `true` if the `DEBUG` environment variable is set to `emittery` or `*`, otherwise `false`.\n\nExample:\n\n```js\nconst Emittery = require('emittery');\n\nEmittery.isDebugEnabled = true;\n\nconst emitter1 = new Emittery({debug: {name: 'myEmitter1'}});\nconst emitter2 = new Emittery({debug: {name: 'myEmitter2'}});\n\nemitter1.on('test', data => {\n\t// …\n});\n\nemitter2.on('otherTest', data => {\n\t// …\n});\n\nemitter1.emit('test');\n//=> [16:43:20.417][emittery:subscribe][myEmitter1] Event Name: test\n//\tdata: undefined\n\nemitter2.emit('otherTest');\n//=> [16:43:20.417][emittery:subscribe][myEmitter2] Event Name: otherTest\n//\tdata: undefined\n```\n\n### emitter = new Emittery(options?)\n\nCreate a new instance of Emittery.\n\n#### options?\n\nType: `object`\n\nConfigure the new instance of Emittery.\n\n##### debug?\n\nType: `object`\n\nConfigure the debugging options for this instance.\n\n###### name\n\nType: `string`\\\nDefault: `undefined`\n\nDefine a name for the instance of Emittery to use when outputting debug data.\n\nExample:\n\n```js\nconst Emittery = require('emittery');\n\nEmittery.isDebugEnabled = true;\n\nconst emitter = new Emittery({debug: {name: 'myEmitter'}});\n\nemitter.on('test', data => {\n\t// …\n});\n\nemitter.emit('test');\n//=> [16:43:20.417][emittery:subscribe][myEmitter] Event Name: test\n//\tdata: undefined\n```\n\n###### enabled?\n\nType: `boolean`\\\nDefault: `false`\n\nToggle debug logging just for this instance.\n\nExample:\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter1 = new Emittery({debug: {name: 'emitter1', enabled: true}});\nconst emitter2 = new Emittery({debug: {name: 'emitter2'}});\n\nemitter1.on('test', data => {\n\t// …\n});\n\nemitter2.on('test', data => {\n\t// …\n});\n\nemitter1.emit('test');\n//=> [16:43:20.417][emittery:subscribe][emitter1] Event Name: test\n//\tdata: undefined\n\nemitter2.emit('test');\n```\n\n###### logger?\n\nType: `Function(string, string, EventName?, Record<string, any>?) => void`\n\nDefault:\n\n```js\n(type, debugName, eventName, eventData) => {\n\tif (typeof eventData === 'object') {\n\t\teventData = JSON.stringify(eventData);\n\t}\n\n\tif (typeof eventName === 'symbol') {\n\t\teventName = eventName.toString();\n\t}\n\n\tconst currentTime = new Date();\n\tconst logTime = `${currentTime.getHours()}:${currentTime.getMinutes()}:${currentTime.getSeconds()}.${currentTime.getMilliseconds()}`;\n\tconsole.log(`[${logTime}][emittery:${type}][${debugName}] Event Name: ${eventName}\\n\\tdata: ${eventData}`);\n}\n```\n\nFunction that handles debug data.\n\nExample:\n\n```js\nconst Emittery = require('emittery');\n\nconst myLogger = (type, debugName, eventName, eventData) => console.log(`[${type}]: ${eventName}`);\n\nconst emitter = new Emittery({\n\tdebug: {\n\t\tname: 'myEmitter',\n\t\tenabled: true,\n\t\tlogger: myLogger\n\t}\n});\n\nemitter.on('test', data => {\n\t// …\n});\n\nemitter.emit('test');\n//=> [subscribe]: test\n```\n\n#### on(eventName | eventName[], listener)\n\nSubscribe to one or more events.\n\nReturns an unsubscribe method.\n\nUsing the same listener multiple times for the same event will result in only one method call per emitted event.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\n\nemitter.on('🦄', data => {\n\tconsole.log(data);\n});\n\nemitter.on(['🦄', '🐶'], data => {\n\tconsole.log(data);\n});\n\nemitter.emit('🦄', '🌈'); // log => '🌈' x2\nemitter.emit('🐶', '🍖'); // log => '🍖'\n```\n\n##### Custom subscribable events\n\nEmittery exports some symbols which represent custom events that can be passed to `Emitter.on` and similar methods.\n\n- `Emittery.listenerAdded` - Fires when an event listener was added.\n- `Emittery.listenerRemoved` - Fires when an event listener was removed.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\n\nemitter.on(Emittery.listenerAdded, ({listener, eventName}) => {\n\tconsole.log(listener);\n\t//=> data => {}\n\n\tconsole.log(eventName);\n\t//=> '🦄'\n});\n\nemitter.on('🦄', data => {\n\t// Handle data\n});\n```\n\n###### Listener data\n\n- `listener` - The listener that was added.\n- `eventName` - The name of the event that was added or removed if `.on()` or `.off()` was used, or `undefined` if `.onAny()` or `.offAny()` was used.\n\nOnly events that are not of this type are able to trigger these events.\n\n##### listener(data)\n\n#### off(eventName | eventName[], listener)\n\nRemove one or more event subscriptions.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\n\nconst listener = data => console.log(data);\n\n(async () => {\n\temitter.on(['🦄', '🐶', '🦊'], listener);\n\tawait emitter.emit('🦄', 'a');\n\tawait emitter.emit('🐶', 'b');\n\tawait emitter.emit('🦊', 'c');\n\temitter.off('🦄', listener);\n\temitter.off(['🐶', '🦊'], listener);\n\tawait emitter.emit('🦄', 'a'); // Nothing happens\n\tawait emitter.emit('🐶', 'b'); // Nothing happens\n\tawait emitter.emit('🦊', 'c'); // Nothing happens\n})();\n```\n\n##### listener(data)\n\n#### once(eventName | eventName[])\n\nSubscribe to one or more events only once. It will be unsubscribed after the first event.\n\nReturns a promise for the event data when `eventName` is emitted.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\n\nemitter.once('🦄').then(data => {\n\tconsole.log(data);\n\t//=> '🌈'\n});\n\nemitter.once(['🦄', '🐶']).then(data => {\n\tconsole.log(data);\n});\n\nemitter.emit('🦄', '🌈'); // Log => '🌈' x2\nemitter.emit('🐶', '🍖'); // Nothing happens\n```\n\n#### events(eventName)\n\nGet an async iterator which buffers data each time an event is emitted.\n\nCall `return()` on the iterator to remove the subscription.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\nconst iterator = emitter.events('🦄');\n\nemitter.emit('🦄', '🌈1'); // Buffered\nemitter.emit('🦄', '🌈2'); // Buffered\n\niterator\n\t.next()\n\t.then(({value, done}) => {\n\t\t// done === false\n\t\t// value === '🌈1'\n\t\treturn iterator.next();\n\t})\n\t.then(({value, done}) => {\n\t\t// done === false\n\t\t// value === '🌈2'\n\t\t// Revoke subscription\n\t\treturn iterator.return();\n\t})\n\t.then(({done}) => {\n\t\t// done === true\n\t});\n```\n\nIn practice, you would usually consume the events using the [for await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) statement. In that case, to revoke the subscription simply break the loop.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\nconst iterator = emitter.events('🦄');\n\nemitter.emit('🦄', '🌈1'); // Buffered\nemitter.emit('🦄', '🌈2'); // Buffered\n\n// In an async context.\nfor await (const data of iterator) {\n\tif (data === '🌈2') {\n\t\tbreak; // Revoke the subscription when we see the value '🌈2'.\n\t}\n}\n```\n\nIt accepts multiple event names.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\nconst iterator = emitter.events(['🦄', '🦊']);\n\nemitter.emit('🦄', '🌈1'); // Buffered\nemitter.emit('🦊', '🌈2'); // Buffered\n\niterator\n\t.next()\n\t.then(({value, done}) => {\n\t\t// done === false\n\t\t// value === '🌈1'\n\t\treturn iterator.next();\n\t})\n\t.then(({value, done}) => {\n\t\t// done === false\n\t\t// value === '🌈2'\n\t\t// Revoke subscription\n\t\treturn iterator.return();\n\t})\n\t.then(({done}) => {\n\t\t// done === true\n\t});\n```\n\n#### emit(eventName, data?)\n\nTrigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.\n\nReturns a promise that resolves when all the event listeners are done. *Done* meaning executed if synchronous or resolved when an async/promise-returning function. You usually wouldn't want to wait for this, but you could for example catch possible errors. If any of the listeners throw/reject, the returned promise will be rejected with the error, but the other listeners will not be affected.\n\n#### emitSerial(eventName, data?)\n\nSame as above, but it waits for each listener to resolve before triggering the next one. This can be useful if your events depend on each other. Although ideally they should not. Prefer `emit()` whenever possible.\n\nIf any of the listeners throw/reject, the returned promise will be rejected with the error and the remaining listeners will *not* be called.\n\n#### onAny(listener)\n\nSubscribe to be notified about any event.\n\nReturns a method to unsubscribe.\n\n##### listener(eventName, data)\n\n#### offAny(listener)\n\nRemove an `onAny` subscription.\n\n#### anyEvent()\n\nGet an async iterator which buffers a tuple of an event name and data each time an event is emitted.\n\nCall `return()` on the iterator to remove the subscription.\n\n```js\nconst Emittery = require('emittery');\n\nconst emitter = new Emittery();\nconst iterator = emitter.anyEvent();\n\nemitter.emit('🦄', '🌈1'); // Buffered\nemitter.emit('🌟', '🌈2'); // Buffered\n\niterator.next()\n\t.then(({value, done}) => {\n\t\t// done === false\n\t\t// value is ['🦄', '🌈1']\n\t\treturn iterator.next();\n\t})\n\t.then(({value, done}) => {\n\t\t// done === false\n\t\t// value is ['🌟', '🌈2']\n\t\t// Revoke subscription\n\t\treturn iterator.return();\n\t})\n\t.then(({done}) => {\n\t\t// done === true\n\t});\n```\n\nIn the same way as for `events`, you can subscribe by using the `for await` statement\n\n#### clearListeners(eventNames?)\n\nClear all event listeners on the instance.\n\nIf `eventNames` is given, only the listeners for that events are cleared.\n\n#### listenerCount(eventNames?)\n\nThe number of listeners for the `eventNames` or all events if not specified.\n\n#### bindMethods(target, methodNames?)\n\nBind the given `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the `target` object.\n\n```js\nimport Emittery = require('emittery');\n\nconst object = {};\n\nnew Emittery().bindMethods(object);\n\nobject.emit('event');\n```\n\n## TypeScript\n\nThe default `Emittery` class has generic types that can be provided by TypeScript users to strongly type the list of events and the data passed to their event listeners.\n\n```ts\nimport Emittery = require('emittery');\n\nconst emitter = new Emittery<\n\t// Pass `{[eventName]: undefined | <eventArg>}` as the first type argument for events that pass data to their listeners.\n\t// A value of `undefined` in this map means the event listeners should expect no data, and a type other than `undefined` means the listeners will receive one argument of that type.\n\t{\n\t\topen: string,\n\t\tclose: undefined\n\t}\n>();\n\n// Typechecks just fine because the data type for the `open` event is `string`.\nemitter.emit('open', 'foo\\n');\n\n// Typechecks just fine because `close` is present but points to undefined in the event data type map.\nemitter.emit('close');\n\n// TS compilation error because `1` isn't assignable to `string`.\nemitter.emit('open', 1);\n\n// TS compilation error because `other` isn't defined in the event data type map.\nemitter.emit('other');\n```\n\n### Emittery.mixin(emitteryPropertyName, methodNames?)\n\nA decorator which mixins `Emittery` as property `emitteryPropertyName` and `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the target class.\n\n```ts\nimport Emittery = require('emittery');\n\n@Emittery.mixin('emittery')\nclass MyClass {}\n\nconst instance = new MyClass();\n\ninstance.emit('event');\n```\n\n## Scheduling details\n\nListeners are not invoked for events emitted *before* the listener was added. Removing a listener will prevent that listener from being invoked, even if events are in the process of being (asynchronously!) emitted. This also applies to `.clearListeners()`, which removes all listeners. Listeners will be called in the order they were added. So-called *any* listeners are called *after* event-specific listeners.\n\nNote that when using `.emitSerial()`, a slow listener will delay invocation of subsequent listeners. It's possible for newer events to overtake older ones.\n\n## Debugging\n\nEmittery can collect and log debug information.\n\nTo enable this feature set the DEBUG environment variable to 'emittery' or '*'. Additionally you can set the static `isDebugEnabled` variable to true on the Emittery class, or `myEmitter.debug.enabled` on an instance of it for debugging a single instance.\n\nSee [API](#api) for more details on how debugging works.\n\n## FAQ\n\n### How is this different than the built-in `EventEmitter` in Node.js?\n\nThere are many things to not like about `EventEmitter`: its huge API surface, synchronous event emitting, magic error event, flawed memory leak detection. Emittery has none of that.\n\n### Isn't `EventEmitter` synchronous for a reason?\n\nMostly backwards compatibility reasons. The Node.js team can't break the whole ecosystem.\n\nIt also allows silly code like this:\n\n```js\nlet unicorn = false;\n\nemitter.on('🦄', () => {\n\tunicorn = true;\n});\n\nemitter.emit('🦄');\n\nconsole.log(unicorn);\n//=> true\n```\n\nBut I would argue doing that shows a deeper lack of Node.js and async comprehension and is not something we should optimize for. The benefit of async emitting is much greater.\n\n### Can you support multiple arguments for `emit()`?\n\nNo, just use [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment):\n\n```js\nemitter.on('🦄', ([foo, bar]) => {\n\tconsole.log(foo, bar);\n});\n\nemitter.emit('🦄', [foo, bar]);\n```\n\n## Related\n\n- [p-event](https://github.com/sindresorhus/p-event) - Promisify an event by waiting for it to be emitted\n",
    "licenseText": "MIT License\n\nCopyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  "artifacts": [],
  "remote": {
    "resolved": "https://registry.yarnpkg.com/emittery/-/emittery-0.10.2.tgz#902eec8aedb8c41938c46e9385e9db7e03182933",
    "type": "tarball",
    "reference": "https://registry.yarnpkg.com/emittery/-/emittery-0.10.2.tgz",
    "hash": "902eec8aedb8c41938c46e9385e9db7e03182933",
    "integrity": "sha512-aITqOwnLanpHLNXZJENbOgjUBeHocD+xsSJmNrjovKBW5HbSpW3d1pEls7GFQPUWXiwG9+0P4GtHfEqC/4M0Iw==",
    "registry": "npm",
    "packageName": "emittery",
    "cacheIntegrity": "sha512-aITqOwnLanpHLNXZJENbOgjUBeHocD+xsSJmNrjovKBW5HbSpW3d1pEls7GFQPUWXiwG9+0P4GtHfEqC/4M0Iw== sha1-kC7siu24xBk4xG6ThenbfgMYKTM="
  },
  "registry": "npm",
  "hash": "902eec8aedb8c41938c46e9385e9db7e03182933"
}