{"id":15416762,"url":"https://github.com/mjancarik/esmj-emitter","last_synced_at":"2026-01-28T21:01:12.977Z","repository":{"id":55957408,"uuid":"523278585","full_name":"mjancarik/esmj-emitter","owner":"mjancarik","description":"Lightweight emitter with zero dependencies for sync/async operation with from listeners result","archived":false,"fork":false,"pushed_at":"2024-10-23T21:03:30.000Z","size":59,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T17:48:06.481Z","etag":null,"topics":["browser","eventemitter","events","javascript","nodejs","pubsub"],"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/mjancarik.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,"zenodo":null}},"created_at":"2022-08-10T09:22:28.000Z","updated_at":"2024-10-23T21:03:34.000Z","dependencies_parsed_at":"2024-03-01T17:45:49.362Z","dependency_job_id":"a6bafc96-2e70-4233-84ff-47f657c35e63","html_url":"https://github.com/mjancarik/esmj-emitter","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"47ce53e26bee61dd938fca1413d8dd059353299e"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/mjancarik/esmj-emitter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjancarik%2Fesmj-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjancarik%2Fesmj-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjancarik%2Fesmj-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjancarik%2Fesmj-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjancarik","download_url":"https://codeload.github.com/mjancarik/esmj-emitter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjancarik%2Fesmj-emitter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28851838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["browser","eventemitter","events","javascript","nodejs","pubsub"],"created_at":"2024-10-01T17:13:47.627Z","updated_at":"2026-01-28T21:01:12.957Z","avatar_url":"https://github.com/mjancarik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Emitter\n\nThe `@esmj/emitter` is tiny (O,9kB) async event emitter library.\n\nIt works in Node.js and the browser (using a bundler like webpack).\n\n## Requirements\n\n- Node 18+\n\n## Install\n\n```shell\nnpm install @esmj/emitter\n```\n\n## Usage\n\nIt works for both Javascript modules (ESM and CJS).\n\n```javascript\nimport { Emitter } from '@esmj/emitter';\n\nconst emitter = new Emitter();\n\nemitter.on('some-event', async (event) =\u003e {\n  return 2 * event.result;\n});\n\nemitter.on('some-event', (event) =\u003e {\n  return 3 * event.result;\n});\n\nemitter.on('some-event', (event) =\u003e {\n  event.stopPropagation();\n});\n\nemitter.on('some-event', async (event) =\u003e {\n  return 4 * event.result;\n});\n\nconst { result } = await emitter.emit('some-event', { result: 1 });\n\nconsole.log(result); // 6\n\n```\n\nOr if you want to use custom name for result from your listeners. You can use `RESULT_KEY` symbol as example below. \n\n```javascript\nimport { Emitter, RESULT_KEY } from '@esmj/emitter';\n\nconst emitter = new Emitter();\n\nemitter.on('some-event', async (event) =\u003e {\n  return 2 * event.count;\n});\n\nemitter.on('some-event', (event) =\u003e {\n  return 3 * event.count;\n});\n\nemitter.on('some-event', (event) =\u003e {\n  event.stopPropagation();\n});\n\nemitter.on('some-event', async (event) =\u003e {\n  return 4 * event.count;\n});\n\nconst { count } = await emitter.emit('some-event', { count: 1, [RESULT_KEY]: 'count' });\n\nconsole.log(count); // 6\n\n```\n\n\n## API\n### emitter = new Emitter(options?)\n\nCreate a new instance of Emitter.\n\n#### options?\n\nType: `object`\n\nConfigure the new instance of Emitter.\n\n##### logger?\n\nType: `object`\nDefault: `console`\n\nConfigure the logger for this instance.\n\n##### debug?\n\nType: `boolean|function(eventName, event)`\nDefault: `false`\n\nConfigure the debugging options for this instance.\n\n#### on(eventName, listener) / addListener(eventName, Listener)\nSubscribe listener for event.\n\nReturns an unsubscribe method.\n\n#### off(eventName, listener) / removeListener(eventName, Listener)\nRemove subscription.\n\n#### once(eventName, listener)\nSubscribe event for listener only once. It will be unsubscribed after the first call.\n\n#### emit(eventName, data?)\n\nTrigger an event asynchronously/synchronously. It is depends on returns value from listener. Listeners are called in the order they were added and executed serially.\n\n#### emitParallel(eventName, data?)\nTrigger an event asynchronously in parallel. The listeners for the event will be executed concurrently and  when the listeners are not dependent on each other.\n\nReturns a promise that resolves with an event, which has result an array of results from the event listeners. The promise is rejected if one of the listeners throws an error.\n\n```javascript\n\nimport { Emitter } from '@esmj/emitter';\n\nconst emitter = new Emitter();\n\nemitter.on('some-event', async (event) =\u003e {\n  return 2 * event.count;\n});\n\nemitter.on('some-event', (event) =\u003e {\n  return 3 * event.count;\n});\n\nemitter.on('some-event', () =\u003e {});\n\nemitter.on('some-event', async (event) =\u003e {\n  return 4 * event.count;\n});\n\nconst { counts } = await emitter.emitParallel('some-event', { count: 1, RESULT_KEY: 'counts' });\n\nconsole.log(counts); // [2, 3, undefined, 4]\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjancarik%2Fesmj-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjancarik%2Fesmj-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjancarik%2Fesmj-emitter/lists"}