{"id":18871868,"url":"https://github.com/foxifyjs/events","last_synced_at":"2025-06-13T04:35:28.457Z","repository":{"id":34361777,"uuid":"177336499","full_name":"foxifyjs/events","owner":"foxifyjs","description":"A high-performance EventEmitter alternative for Node.js and browser","archived":false,"fork":false,"pushed_at":"2023-05-07T09:04:27.000Z","size":1650,"stargazers_count":19,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T14:01:52.325Z","etag":null,"topics":["benchmarks","browser","emitter","event","eventemitter","eventemitter2","eventemitter3","events","javascript","node","nodejs","strict-events","typescript"],"latest_commit_sha":null,"homepage":"https://foxifyjs.github.io/events","language":"JavaScript","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/foxifyjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"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},"funding":{"open_collective":"foxify"}},"created_at":"2019-03-23T20:23:39.000Z","updated_at":"2024-07-09T19:12:13.000Z","dependencies_parsed_at":"2023-10-12T04:52:11.965Z","dependency_job_id":null,"html_url":"https://github.com/foxifyjs/events","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":"0.021276595744680882","last_synced_commit":"c23f8edc3e213cf16060edd7cd377232bba36896"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fevents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fevents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fevents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Fevents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foxifyjs","download_url":"https://codeload.github.com/foxifyjs/events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248521139,"owners_count":21118006,"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":["benchmarks","browser","emitter","event","eventemitter","eventemitter2","eventemitter3","events","javascript","node","nodejs","strict-events","typescript"],"created_at":"2024-11-08T05:27:47.940Z","updated_at":"2025-04-14T15:33:00.480Z","avatar_url":"https://github.com/foxifyjs.png","language":"JavaScript","funding_links":["https://opencollective.com/foxify"],"categories":[],"sub_categories":[],"readme":"# Events\n\n`@foxify/events` is a `EventEmitter` alternative for `Node.js` and `browser` that has been optimized for better\nperformance compared to the native version.\n\n[![Build Status][BUILD_BADGE]][BUILD_URI]\n[![Coverage Status][COVERAGE_BADGE]][COVERAGE_URI]\n[![NPM Version][VERSION_BADGE]][NPM_URI]\n[![npm bundle size (minified)][MINIFIED_BADGE]][NPM_URI]\n[![npm bundle size (minified + gzip)][GZIP_BADGE]][NPM_URI]\n[![NPM Monthly Downloads][MONTHLY_DOWNLOADS_BADGE]][NPM_URI]\n[![NPM Total Downloads][TOTAL_DOWNLOADS_BADGE]][NPM_URI]\n[![Dependencies Status][DEPENDENCY_STATUS_BADGE]][DEPENDENCY_STATUS_URI]\n[![Open Issues][OPEN_ISSUES_BADGE]][OPEN_ISSUES_URI]\n[![Pull Requests][PR_BADGE]][PR_URI]\n[![License][LICENSE_BADGE]][LICENSE_URI]\n\nThis module is API compatible with the `EventEmitter` that ships by default with Node.js but there are some slight\ndifferences:\n\n- The `newListener` and `removeListener` events have been removed as they are useful only in some uncommon use-cases.\n- The `setMaxListeners` and `getMaxListeners` methods are not available.\n- Support for custom context for events so there is no need to use `bind`.\n- Support for strict events in `TypeScript`.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Strict events](#strict-events)\n  - [Contextual emits](#contextual-emits)\n- [Benchmarks](#benchmarks)\n- [Tests](#tests)\n- [Coverage](#coverage)\n- [Versioning](#versioning)\n- [Authors](#authors)\n- [License](#license)\n\n## Installation\n\n```shell\nnpm i @foxify/events\n```\n\n## Usage\n\nJavaScript:\n\n```javascript\nconst EventEmitter = require(\"@foxify/events\").default;\n```\n\nTypeScript:\n\n```typescript\nimport EventEmitter from \"@foxify/events\";\n```\n\nFor the API documentation, please follow the official Node.js [documentation](https://nodejs.org/api/events.html).\n\n### Strict events\n\n\u003e \"error\" event is always defined by default because of its different behavior\n\nfirst create events type (optional)\n\n```typescript\ntype Events = {\n  foo: (bar: string) =\u003e void;\n  withContextEnforcement: (this: number, bar: number) =\u003e void;\n}\n```\n\nthen create a new direct/extended instance\n\n```typescript\nconst eventEmitter = new EventEmitter\u003cEvents\u003e();\n```\n\n```typescript\nclass Emitter extends EventEmitter\u003cEvents\u003e {\n}\n\nconst eventEmitter = new Emitter();\n```\n\nthen start emitting \u0026 listening to events\n\n```typescript\n// Works just fine. so don't worry about \"ImplicitAny\" config, since type of \"bar\" is defined as \"string\"\neventEmitter.on(\"foo\", bar =\u003e 1);\n\n// This works fine as well\neventEmitter.on(\"withContextEnforcement\", function (bar) {\n  return this + bar;\n}, 1);\n\n// Throws an error (TS compile time), since this event requires the \"bar\" argument of type \"string\"\neventEmitter.emit(\"foo\");\n\n// Works just fine\neventEmitter.emit(\"foo\", \"bar\");\n```\n\n### Contextual emits\n\nWe've upgraded the API of the `on`, `once`, `addListener`, `prependListener` and\n`prependOnceListener` to accept an extra argument which is the `context`\nor `this` value that should be set for the emitted events. This means you no longer have the overhead of an event that\nrequired `bind` in order to get a custom `this` value.\n\n```javascript\nconst eventEmitter = new EventEmitter();\nconst context = { foo: \"bar\" };\n\nfunction listener() {\n  console.log(this === context); // true\n}\n\neventEmitter.on(\"event:1\", listener, context);\neventEmitter.once(\"event:2\", listener, context);\neventEmitter.addListener(\"event:3\", listener, context);\neventEmitter.prependListener(\"event:4\", listener, context);\neventEmitter.prependOnceListener(\"event:5\", listener, context);\n```\n\n## Benchmarks\n\n```shell\nnpm run benchmarks\n```\n\n## Tests\n\n```shell\nnpm test\n```\n\n## Coverage\n\n```shell\nnpm run test:coverage\n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org) for versioning. For the versions available, see\nthe [releases on this repository](https://github.com/foxifyjs/events/releases).\n\n## Authors\n\n- **Ardalan Amini** - *Core Maintainer* - [@ardalanamini](https://github.com/ardalanamini)\n\nSee also the list of [contributors](https://github.com/foxifyjs/events/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE][LICENSE_URI] file for details\n\n\n[BUILD_BADGE]: https://github.com/foxifyjs/events/workflows/Test/badge.svg\n\n[BUILD_URI]: https://github.com/foxifyjs/events/actions\n\n[COVERAGE_BADGE]: https://codecov.io/gh/foxifyjs/events/branch/master/graph/badge.svg\n\n[COVERAGE_URI]: https://codecov.io/gh/foxifyjs/events\n\n[VERSION_BADGE]: https://img.shields.io/npm/v/@foxify/events.svg\n\n[MINIFIED_BADGE]: https://img.shields.io/bundlephobia/min/@foxify/events.svg\n\n[GZIP_BADGE]: https://img.shields.io/bundlephobia/minzip/@foxify/events.svg\n\n[MONTHLY_DOWNLOADS_BADGE]: https://img.shields.io/npm/dm/@foxify/events.svg\n\n[TOTAL_DOWNLOADS_BADGE]: https://img.shields.io/npm/dt/@foxify/events.svg\n\n[DEPENDENCY_STATUS_BADGE]: https://david-dm.org/foxifyjs/events.svg\n\n[DEPENDENCY_STATUS_URI]: https://david-dm.org/foxifyjs/events\n\n[OPEN_ISSUES_BADGE]: https://img.shields.io/github/issues-raw/foxifyjs/events.svg\n\n[OPEN_ISSUES_URI]: https://github.com/foxifyjs/events/issues?q=is%3Aopen+is%3Aissue\n\n[PR_BADGE]: https://img.shields.io/badge/PRs-Welcome-brightgreen.svg\n\n[PR_URI]: https://github.com/foxifyjs/events/pulls\n\n[LICENSE_BADGE]: https://img.shields.io/github/license/foxifyjs/events.svg\n\n[LICENSE_URI]: https://github.com/foxifyjs/events/blob/master/LICENSE\n\n[NPM_URI]: https://www.npmjs.com/package/@foxify/events\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxifyjs%2Fevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoxifyjs%2Fevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxifyjs%2Fevents/lists"}