{"_id":"@2k/ee","_rev":"1-a94889b34f88cc5cb1d0011b14723dc4","name":"@2k/ee","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@2k/ee","version":"0.0.1","description":"Tiny, typed event emitter utility for Node.js and browsers.","author":{"name":"scriptpower"},"keywords":["event","events","emitter","EventEmitter","micro","tiny","nodejs","browser","typescript"],"type":"module","types":"./lib/index.d.ts","main":"./lib/index.cjs","module":"lib/index.js","unpkg":"lib/index.iife.js","jsdelivr":"lib/index.iife.js","exports":{".":{"import":{"types":"./lib/index.d.ts","default":"./lib/index.js"},"require":{"types":"./lib/index.d.ts","default":"./lib/index.cjs"}}},"scripts":{},"publishConfig":{"registry":"https://registry.npmjs.org/","access":"public"},"license":"MIT","_id":"@2k/ee@0.0.1","gitHead":"c4b01c2d1dde580ec50f430ac5b29e72ad346250","_nodeVersion":"20.6.1","_npmVersion":"10.2.0","dist":{"integrity":"sha512-tWk1NV3BBaRtSHh+97WUg0Her+9gchm/NWSFJomXNkDaIqe+39uIvn5rWbVaGeExltgFB9Uob/alzE4rzHC9Ig==","shasum":"2f3032fdb6b9cd56df87bbe8cdbc07555740a46e","tarball":"https://registry.npmjs.org/@2k/ee/-/ee-0.0.1.tgz","fileCount":6,"unpackedSize":4869,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEwRv334jtUQ+1mWiUJ9i0yD27jMPj5w1qVRsET9edMcAiEAw2XhtcPO0HWTXHPVo0W++DOQfj+JYRUq0rIkr5uZFfo="}]},"_npmUser":{"name":"scriptpower","email":"scriptpower@qq.com"},"directories":{},"maintainers":[{"name":"scriptpower","email":"scriptpower@qq.com"},{"name":"leiyl","email":"leiyl@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ee_0.0.1_1699142362391_0.9337149777644973"},"_hasShrinkwrap":false}},"time":{"created":"2023-11-04T23:59:22.272Z","0.0.1":"2023-11-04T23:59:22.587Z","modified":"2023-11-05T00:00:54.059Z"},"maintainers":[{"email":"scriptpower@qq.com","name":"scriptpower"}],"description":"Tiny, typed event emitter utility for Node.js and browsers.","keywords":["event","events","emitter","EventEmitter","micro","tiny","nodejs","browser","typescript"],"author":{"name":"scriptpower"},"license":"MIT","readme":"# EE (Event Emitter)\n\n> Tiny, typed event emitter utility for Node.js and browsers. No dependencies.\n\n_Need a single event and type, only? Use [Signal](https://www.npmjs.com/package/@2k/signal) instead_\n\n## Installation\n\n```sh\nnpm install @2k/ee --save\n```\n\n## Usage (TypeScript)\n\n```typescript\nimport { EE } from '@2k/ee';\n\n// map event names to their callback param types\ninterface Events {\n  a: number;\n  b: string;\n  c: undefined;\n}\n\nconst ee = new EE<Events>();\n\nconst cb = (num: number) => console.log('A', num);\n\nee.on('a', cb);\nee.on('b', str => console.log('B', str));\nee.once('c', () => console.log('C'));\n\nee.emit('a', 123);\nee.emit('b', 'hello');\nee.emit('c');\n\nee.off('a', cb);\n\nee.event('b', 123); // error\nee.event('d', 123); // error\n```\n\n## Methods\n\n### `on(event, fn)`\n\nAttaches an event handler to be called whenever the event fires.\n\n### `once(event, fn)`\n\nAttaches a one-time handler which is unbound after it fires the first time.\n\n### `off(event, fn?)`\n\nDetaches one instance of a given handler from the event emitter. If no handler is provided, detaches all handlers.\n\n### `emit(event, arg)`\n\nFires the event synchronously, triggering any attached handlers with the given `arg`.\n\n### `event(event, arg)`\n\nFires the event asynchronously, triggering any attached handlers with the given `arg`. Useful when attaching handlers later in the same event loop turn.\n","readmeFilename":"readme.md"}