{"id":19197003,"url":"https://github.com/jitesoft/js-events","last_synced_at":"2025-08-31T19:46:00.738Z","repository":{"id":34678949,"uuid":"155175076","full_name":"jitesoft/js-events","owner":"jitesoft","description":"Event handler for javascript.","archived":false,"fork":false,"pushed_at":"2025-03-17T02:06:59.000Z","size":1957,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T03:25:09.731Z","etag":null,"topics":["async","callback","event-handler","events","hacktoberfest","javascript","js","listener"],"latest_commit_sha":null,"homepage":"","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/jitesoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.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}},"created_at":"2018-10-29T08:12:51.000Z","updated_at":"2022-01-08T13:34:04.000Z","dependencies_parsed_at":"2025-03-17T03:24:38.532Z","dependency_job_id":"9efbd408-8437-4942-92bb-12a0dee3f32a","html_url":"https://github.com/jitesoft/js-events","commit_stats":null,"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"purl":"pkg:github/jitesoft/js-events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fjs-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fjs-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fjs-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fjs-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jitesoft","download_url":"https://codeload.github.com/jitesoft/js-events/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jitesoft%2Fjs-events/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273032930,"owners_count":25034067,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["async","callback","event-handler","events","hacktoberfest","javascript","js","listener"],"created_at":"2024-11-09T12:15:15.453Z","updated_at":"2025-08-31T19:46:00.684Z","avatar_url":"https://github.com/jitesoft.png","language":"JavaScript","readme":"# Events\n\n[![npm (scoped)](https://img.shields.io/npm/v/@jitesoft/events)](https://www.npmjs.com/package/@jitesoft/events)\n[![Known Vulnerabilities](https://dev.snyk.io/test/npm/@jitesoft/events/badge.svg)](https://dev.snyk.io/test/npm/@jitesoft/events)\n[![pipeline status](https://gitlab.com/jitesoft/open-source/javascript/events/badges/master/pipeline.svg)](https://gitlab.com/jitesoft/open-source/javascript/events/commits/master)\n[![coverage report](https://gitlab.com/jitesoft/open-source/javascript/events/badges/master/coverage.svg)](https://gitlab.com/jitesoft/open-source/javascript/events/commits/master)\n[![npm](https://img.shields.io/npm/dt/@jitesoft/events)](https://www.npmjs.com/package/@jitesoft/events)\n[![Back project](https://img.shields.io/badge/Open%20Collective-Tip%20the%20devs!-blue.svg)](https://opencollective.com/jitesoft-open-source)\n\nA simple event handling system for browser and node alike.\n\n---\n\n## Installation\n\nInstall will npm or yarn:\n\n```bash\nnpm install @jitesoft/events\nyarn add @jitesoft/events\n```\n\n## Classes\n\nThe event handler class is the main instance which handles listening and emitting of events.\n\n### EventHandler\n\nThe following methods are exposed on the event handler:\n\n`on(string: eventName, function: listener, number: priority = 0, boolean: once = false): number`\n\nThe `on` method attaches a callback to the handler which will be fired once the given event is emitted by the handler.  \nIt's possible to set a priority on the callback by changing the priority `number` value, where 0 is lowest priority. The `once` argument\ndetermines if the callback should be removed after first run or not and defaults to `false`.  \nThe method returns a handle id (`number`) which can be used to remove the event listener if wanted.\n\nIf the listener callback returns FALSE, the event will not bubble to the next handler.\n\n`once(string: eventName, function: listener, number: priority): number`\n\nThe `once` method does pretty much the same as `on`, but is always a `fire once` listener type.\n\n`clear(): void`\n\nClear empties all the listeners from the handler.\n\n`off(string: eventName, function|number: listener): boolean`\n\nThe `off` method removes a given listener from the handler either by its handle or by passing its callback method.\n\n`emit(string: eventName, Event: event): void`\n\nEmits a event and fires each listener that listens to the given event.\n\n`emitAsync(string: eventName, Event: event, boolean: throw = false): Promise\u003cvoid\u003e`\n\nThe emitAsync method works just like the Emit method, with the exception that it is an async method.  \nWhen used, it will group all the listeners by their priority and call them in batches, and just as with `emit`, if \none of the callback returns false, it will not call the next batch.\n\nIt uses the `Promise.allSettled` function - by default - which does not throw exceptions from the listeners.\nIf the `throw` parameter is passed, it will instead use `all` which will throw exceptions from the listeners.\n\n### Event\n\nWhen emitting a event, the `Event` class is used as a object which passes the data. It accepts a `data` object, which can be accessed\nvia the exposed `data` getter and an optional `callee` argument which can be used to pass information (or a reference) to the calling object.  \n\n---\n\n## Example\n\nThe following example shows the most simple way create a handler and a listener and emit an event.\n\n```javascript\nimport { EventHandler, Event } from '@jitesoft/events';\n\nconst handler = new Handler();\n\nhandler.on('test-event', (event) =\u003e {\n  console.log(event.data.message);\n});\n\nhandler.emit('test-event', new Event({\n  message: 'This is a simple example...'\n}));\n```\n\n---\n\n## License\n\n```text\nMIT License\n\nCopyright (c) 2018 Jitesoft\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","funding_links":["https://opencollective.com/jitesoft-open-source"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitesoft%2Fjs-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjitesoft%2Fjs-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjitesoft%2Fjs-events/lists"}