{"_id":"@darco2903/typed-emitter","_rev":"3-620cf6b038eb1705c4d9093e23c42782","name":"@darco2903/typed-emitter","dist-tags":{"beta":"1.2.2-beta.0","latest":"1.3.1"},"versions":{"1.2.2-beta.0":{"name":"@darco2903/typed-emitter","version":"1.2.2-beta.0","keywords":[],"author":{"name":"Darco2903"},"license":"ISC","_id":"@darco2903/typed-emitter@1.2.2-beta.0","maintainers":[{"name":"darco2903","email":"william.valenduc@orange.fr"}],"homepage":"https://github.com/Darco2903/typed-emitter#readme","bugs":{"url":"https://github.com/Darco2903/typed-emitter/issues"},"dist":{"shasum":"a08536dfc0a60172d5a3870c1f19c6fba478260d","tarball":"https://registry.npmjs.org/@darco2903/typed-emitter/-/typed-emitter-1.2.2-beta.0.tgz","fileCount":9,"integrity":"sha512-VOv9niCjKc7ZuPwl0rFFCxFjeSfM0fVCyp43SoTOT4+ugXP5f+kNWKxKSAQ0vK27uCxN487tnCtzry+Fx/Hc1A==","signatures":[{"sig":"MEUCIGpfyy1K8dP9AogRXDDPqsX5X9oOX66LCL9OF1TagJbOAiEAiyKJlHw53ASnM+eXNbsvcaoZ/X8bVEnGQhNpZ9vaIXI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":42577},"main":"dist/index.js","type":"module","_from":"file:darco2903-typed-emitter-1.2.2-beta.0.tgz","types":"dist/index.d.ts","scripts":{"test":"vitest","build":"tsc","clean":"rimraf -g dist darco2903-typed-emitter-*.tgz"},"_npmUser":{"name":"darco2903","email":"william.valenduc@orange.fr"},"_resolved":"C:\\Users\\Will\\AppData\\Local\\Temp\\c87e0a8dd60052086a8a9b540dc5ed6f\\darco2903-typed-emitter-1.2.2-beta.0.tgz","_integrity":"sha512-VOv9niCjKc7ZuPwl0rFFCxFjeSfM0fVCyp43SoTOT4+ugXP5f+kNWKxKSAQ0vK27uCxN487tnCtzry+Fx/Hc1A==","repository":{"url":"git+https://github.com/Darco2903/typed-emitter.git"},"_npmVersion":"11.6.2","description":"`Typed Emitter` is a TypeScript library that provides a strongly-typed event emitter. It allows to define event types and their corresponding listener signatures, ensuring type safety when emitting events and registering listeners.","directories":{},"_nodeVersion":"24.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^6.1.0","vitest":"^3.2.4","typescript":"^5.9.3","@types/node":"^24.10.1"},"_npmOperationalInternal":{"tmp":"tmp/typed-emitter_1.2.2-beta.0_1772804908377_0.10073053429081158","host":"s3://npm-registry-packages-npm-production"}},"1.3.0":{"name":"@darco2903/typed-emitter","version":"1.3.0","keywords":[],"author":{"name":"Darco2903"},"license":"ISC","_id":"@darco2903/typed-emitter@1.3.0","maintainers":[{"name":"darco2903","email":"william.valenduc@orange.fr"}],"homepage":"https://github.com/Darco2903/typed-emitter#readme","bugs":{"url":"https://github.com/Darco2903/typed-emitter/issues"},"dist":{"shasum":"375721c62195fd6206c1abf11086f64ba9a1d7d6","tarball":"https://registry.npmjs.org/@darco2903/typed-emitter/-/typed-emitter-1.3.0.tgz","fileCount":11,"integrity":"sha512-rhvwgAWR+X3bgUGLQlLd163pbVe6yV1yQWucJi7H+8RP1vdyqw9yaj9e8m5IWhJwNpJg66hmEG6srSn2h4yVUw==","signatures":[{"sig":"MEQCIBkDYCzdol6iI67Di/dknYdxX19UjlVQMhzQLl+g9tQiAiBbX8C7JhX0+NJDJk5VazHk+v0kGHZBq/m8dWlLFmtjxA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@darco2903%2ftyped-emitter@1.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":49285},"main":"dist/index.js","type":"module","_from":"file:darco2903-typed-emitter-1.3.0.tgz","types":"dist/index.d.ts","scripts":{"test":"vitest","build":"tsc","clean":"rimraf -g dist darco2903-typed-emitter-*.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:93cbcfde-74e8-4c8d-b2ef-3727966fb8a7"}},"_resolved":"/tmp/2e1fd17c34e882d42b8569fa4e9aef71/darco2903-typed-emitter-1.3.0.tgz","_integrity":"sha512-rhvwgAWR+X3bgUGLQlLd163pbVe6yV1yQWucJi7H+8RP1vdyqw9yaj9e8m5IWhJwNpJg66hmEG6srSn2h4yVUw==","repository":{"url":"git+https://github.com/Darco2903/typed-emitter.git"},"_npmVersion":"11.9.0","description":"Typed Emitter is a TypeScript library that provides a strongly-typed event emitter. It allows to define event types and their corresponding listener signatures, ensuring type safety when emitting events and registering listeners.","directories":{},"_nodeVersion":"24.14.0","dependencies":{"neverthrow":"^8.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"rimraf":"^6.1.3","vitest":"^4.0.18","typescript":"^5.9.3","@types/node":"^25.3.5"},"peerDependencies":{"@darco2903/secondthought":"^1.1.0"},"_npmOperationalInternal":{"tmp":"tmp/typed-emitter_1.3.0_1772818986454_0.05891251366607775","host":"s3://npm-registry-packages-npm-production"}},"1.3.1":{"name":"@darco2903/typed-emitter","version":"1.3.1","author":{"name":"Darco2903"},"description":"Typed Emitter is a TypeScript library that provides a strongly-typed event emitter. It allows to define event types and their corresponding listener signatures, ensuring type safety when emitting events and registering listeners.","keywords":[],"license":"ISC","main":"dist/index.js","types":"dist/index.d.ts","type":"module","repository":{"url":"git+https://github.com/Darco2903/typed-emitter.git"},"publishConfig":{"access":"public"},"dependencies":{"neverthrow":"^8.2.0"},"peerDependencies":{"@darco2903/secondthought":"^1.1.0"},"devDependencies":{"@types/node":"^25.3.5","rimraf":"^6.1.3","typescript":"^5.9.3","vitest":"^4.0.18"},"scripts":{"build":"tsc","test":"vitest","clean":"rimraf -g dist darco2903-typed-emitter-*.tgz"},"_id":"@darco2903/typed-emitter@1.3.1","bugs":{"url":"https://github.com/Darco2903/typed-emitter/issues"},"homepage":"https://github.com/Darco2903/typed-emitter#readme","_integrity":"sha512-f0/TFgQQt6P7htSR7Zc7ZEtsMWu+Nqf31hnlbfhl0aV2sZHi3zMVfLehQsvPMz5vzhfjCTTsKqi09Of+VBSYCw==","_resolved":"/tmp/26e11b065a60b6ed20e7152ca1268847/darco2903-typed-emitter-1.3.1.tgz","_from":"file:darco2903-typed-emitter-1.3.1.tgz","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-f0/TFgQQt6P7htSR7Zc7ZEtsMWu+Nqf31hnlbfhl0aV2sZHi3zMVfLehQsvPMz5vzhfjCTTsKqi09Of+VBSYCw==","shasum":"d508b262b829d57a96af8b8ae7185b2d76dd28e7","tarball":"https://registry.npmjs.org/@darco2903/typed-emitter/-/typed-emitter-1.3.1.tgz","fileCount":11,"unpackedSize":15183,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@darco2903%2ftyped-emitter@1.3.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIH8O6Cx7Srpi+QYQl2zQvIn8HwaxJ1pLiH10iM20Iuq6AiBlD+4p7GgPnAN33Jom4YJsrlHCCXGkyAUIX0/5b8zFFQ=="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:93cbcfde-74e8-4c8d-b2ef-3727966fb8a7"}},"directories":{},"maintainers":[{"name":"darco2903","email":"william.valenduc@orange.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/typed-emitter_1.3.1_1773786898035_0.12249252911328279"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-06T13:48:28.314Z","modified":"2026-03-17T22:34:58.473Z","1.2.2-beta.0":"2026-03-06T13:48:28.606Z","1.3.0":"2026-03-06T17:43:06.627Z","1.3.1":"2026-03-17T22:34:58.186Z"},"bugs":{"url":"https://github.com/Darco2903/typed-emitter/issues"},"author":{"name":"Darco2903"},"license":"ISC","homepage":"https://github.com/Darco2903/typed-emitter#readme","keywords":[],"repository":{"url":"git+https://github.com/Darco2903/typed-emitter.git"},"description":"Typed Emitter is a TypeScript library that provides a strongly-typed event emitter. It allows to define event types and their corresponding listener signatures, ensuring type safety when emitting events and registering listeners.","maintainers":[{"name":"darco2903","email":"william.valenduc@orange.fr"}],"readme":"# Typed Emitter\n\n## Description\n\nTyped Emitter is a TypeScript library that provides a strongly-typed event emitter. It allows to define event types and their corresponding listener signatures, ensuring type safety when emitting events and registering listeners.\n\n## Features\n\n- Strongly-typed event definitions and listeners\n- TypedEmitterProtected class for protected access to the emitter instance\n- `onceAsync` method for awaiting a single occurrence of an event\n- `waitFor` method for waiting for an event with optional timeout and condition\n- Integration with `neverthrow` for robust error handling in asynchronous event waiting\n- Optional integration with `@darco2903/secondthought` for typed timespans\n\n> **Note**: `waitFor` method uses [**neverthrow**](https://www.npmjs.com/package/neverthrow) to provide a robust way to handle asynchronous event waiting with proper error handling.\n> It also supports integration with [**@darco2903/secondthought**](https://www.npmjs.com/package/@darco2903/secondthought), allowing you to use typed timespans for timeouts when waiting for events. This integration is optional but recommended for enhanced type safety and convenience.\n\n## Installation\n\n```bash\nnpm install @darco2903/typed-emitter\n```\n\n## TypedEmitterProtected\n\nThe `TypedEmitterProtected` class is a base class that provides protected access to the emitter instance. It can be extended by other classes to create their own typed emitters while keeping the emitter instance protected. It allows you to define your own methods that can emit events using the protected `_emit` method, while preventing external code from directly emitting events.\n\n```ts\nimport { TypedEmitterProtected } from \"@darco2903/typed-emitter\";\n\ninterface MyEvents {\n    event: [{ id: number; name: string }];\n}\n\nclass MyEmitter extends TypedEmitterProtected<MyEvents> {\n    constructor() {\n        super();\n    }\n\n    public triggerEvent(id: number, name: string) {\n        this._emit(\"event\", { id, name }); // protected method that actually emits the event\n    }\n}\n\nconst emitter = new MyEmitter();\n\nemitter.on(\"event\", (data) => {\n    console.log(\"Received event:\", data);\n});\n\nemitter.triggerEvent(1, \"Test\"); // This will log: Received event: { id: 1, name: 'Test' }\n\nemitter.emit(\"event\", { id: 2, name: \"Another Test\" }); // This will not log anything, as the protected method is not called\n```\n\n## Example Usage\n\n### Basic Event Emitter\n\n```ts\nimport { TypedEmitter } from \"@darco2903/typed-emitter\";\n\nconst emitter = new TypedEmitter<{\n    message: [message: string];\n    userConnected: [userId: number, username: string];\n}>();\n\nemitter.on(\"message\", (message) => {\n    console.log(`Received message: ${message}`);\n});\n\nemitter.emit(\"message\", \"Hello, World!\");\n\nemitter.on(\"userConnected\", (userId, username) => {\n    console.log(`User connected: ${username} (ID: ${userId})`);\n});\n\nemitter.emit(\"userConnected\", 1, \"Bob\");\n```\n\n### Using `onceAsync` and `waitFor`\n\n```ts\nimport { TypedEmitter } from \"@darco2903/typed-emitter\";\n\nexport interface MyEvents {\n    event1: [{ id: number; name: string }];\n    event2: [boolean];\n    event3: [{ a: number; b: string }];\n}\n\nconst emitter = new TypedEmitter<MyEvents>();\n\n// will wait for \"event1\" to be emitted and resolve with the event arguments\nconst [{ id, name }] = await emitter.onceAsync(\"event1\");\n\n// no options, will wait indefinitely until event2 is emitted\nawait emitter.waitFor(\"event2\");\n\n// will wait for event2 to be emitted, but will resolve with an Err if it takes longer than 1000ms\nawait emitter.waitFor(\"event2\", { timeout: 1000 });\n\n// will wait for event3 to be emitted, but will only resolve if the condition is met (a > 0 and b === \"Hello\")\nawait emitter.waitFor(\"event3\", { condition: ({ a, b }) => a > 0 && b === \"Hello\" });\n\n// will wait for event2 to be emitted, but will only resolve if the condition is met (v is true) and will resolve with an Err if it takes longer than 1000ms\nawait emitter.waitFor(\"event2\", { timeout: 1000, condition: (v) => v });\n\n// Full example with both timeout and condition:\n\nawait emitter\n    .waitFor(\"event1\", {\n        timeout: 1000,\n        condition: ({ id }) => id > 0,\n    })\n    .match(\n        ([{ id, name }]) => {\n            // event was emitted and condition was met\n            console.log(\"Event received:\", id, name);\n        },\n        () => {\n            // timeout was reached before event was emitted\n            console.error(\"Failed to wait for event: timeout reached\");\n        },\n    );\n```\n\n### SecondThought Integration\n\n```ts\nimport { TypedEmitter } from \"@darco2903/typed-emitter\";\nimport { Second } from \"@darco2903/secondthought\";\n\nconst emitter = new TypedEmitter<{\n    event: [number];\n}>();\n\n// will wait for \"event\" to be emitted, but will resolve with an Err if it takes longer than 2 seconds\nawait emitter.waitFor(\"event\", { timeout: new Second(2) });\n```\n","readmeFilename":"README.md"}