{"id":16439153,"url":"https://github.com/posva/event-emitter","last_synced_at":"2025-04-08T03:17:09.744Z","repository":{"id":239178826,"uuid":"798722992","full_name":"posva/event-emitter","owner":"posva","description":"\u003c200 bytes type safe extendable event emitter / pubsub class","archived":false,"fork":false,"pushed_at":"2024-10-24T07:52:45.000Z","size":182,"stargazers_count":44,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-25T04:10:39.343Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://event-emitter.esm.is/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posva.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"posva"}},"created_at":"2024-05-10T10:42:54.000Z","updated_at":"2024-10-24T22:40:37.000Z","dependencies_parsed_at":"2024-05-10T14:43:11.572Z","dependency_job_id":"442bb508-18fa-423f-a3ef-0bf2b1b2c10d","html_url":"https://github.com/posva/event-emitter","commit_stats":null,"previous_names":["posva/event-emitter"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fevent-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fevent-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fevent-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fevent-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posva","download_url":"https://codeload.github.com/posva/event-emitter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767237,"owners_count":20992548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T09:08:12.934Z","updated_at":"2025-04-08T03:17:09.690Z","avatar_url":"https://github.com/posva.png","language":"TypeScript","funding_links":["https://github.com/sponsors/posva"],"categories":[],"sub_categories":[],"readme":"# EventEmitter [![ci](https://github.com/posva/event-emitter/actions/workflows/ci.yml/badge.svg)](https://github.com/posva/event-emitter/actions/workflows/ci.yml) [![npm package](https://badgen.net/npm/v/@posva/event-emitter?)](https://www.npmjs.com/package/@posva/event-emitter) [![codecov](https://codecov.io/github/posva/event-emitter/graph/badge.svg?token=37fOzdCXYi)](https://codecov.io/github/posva/event-emitter) [![thanks](https://badgen.net/badge/thanks/♥/pink)](https://esm.dev/open-source)\n\n\u003e Typed event and lightweight event emitter with a class based API\n\n- ⛓️ **Typed**: Powerful autocompletion and type checking\n- 📦 **Class based**: Add event emitting to your classes\n- 💨 **Lightweight**: 188 bytes min+brotli\n- 🌐 **Runtime Agnostic**: Works everywhere: Browser, node, Bun...\n\n## Installation\n\n```sh\nnpm i @posva/event-emitter\n```\n\n## Usage\n\n```ts\nimport { EventEmitter } from '@posva/event-emitter'\n\nconst emitter = new EventEmitter\u003c{\n  // Define the events you want to emit and their arguments\n  start: []\n  // non tuples are also supported\n  end: { reason: string }\n\n  // You can also define multiple arguments\n  sum: [number, number]\n}\u003e()\n\n// no arguments\nemitter.emit('start')\n// object payload\nemitter.emit('end', { reason: 'finished' })\n// multiple arguments\nemitter.emit('sum', 1, 2)\n\nemitter.on('end', ({ reason }) =\u003e console.log('ended:', reason))\n\n// You can also listen to all events\n\nemitter.on('*', (event, payload) =\u003e {\n  if (event === 'end') {\n    // payload is always an array\n    const [{ reason }] = payload\n  } else if (event === 'sum') {\n    const [a, b] = payload\n  }\n})\n```\n\nSince `EventEmitter` is a class, you can extend it in your own classes:\n\n```ts\nclass CardGame extends EventEmitter\u003c{\n  start: []\n  end: { winner: string }\n  draw: [player: string, card: string]\n  play: [player: string, card: string]\n}\u003e {\n  start() {\n    this.emit('start')\n  }\n\n  end(winner: string) {\n    this.emit('end', { winner })\n  }\n}\n```\n\n## API\n\nMost of the code can be discovered through the autocompletion but the API documentation is available at [https://event-emitter.esm.is](https://event-emitter.esm.is).\n\n## Related\n\n- [mitt](https://github.com/developit/mitt): this library is a fork of mitt with a class based API and better types\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposva%2Fevent-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposva%2Fevent-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposva%2Fevent-emitter/lists"}