{"id":22349133,"url":"https://github.com/mnasyrov/pubsub","last_synced_at":"2025-07-30T06:31:12.995Z","repository":{"id":35071227,"uuid":"203193276","full_name":"mnasyrov/pubsub","owner":"mnasyrov","description":"Simple PubSub for Typescript","archived":false,"fork":false,"pushed_at":"2023-01-04T07:35:55.000Z","size":1228,"stargazers_count":5,"open_issues_count":15,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T18:30:57.698Z","etag":null,"topics":["emitter","pubsub","typescript"],"latest_commit_sha":null,"homepage":"","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/mnasyrov.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}},"created_at":"2019-08-19T14:50:54.000Z","updated_at":"2025-02-26T15:20:38.000Z","dependencies_parsed_at":"2023-01-15T13:12:51.685Z","dependency_job_id":null,"html_url":"https://github.com/mnasyrov/pubsub","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/mnasyrov/pubsub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnasyrov%2Fpubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnasyrov%2Fpubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnasyrov%2Fpubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnasyrov%2Fpubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnasyrov","download_url":"https://codeload.github.com/mnasyrov/pubsub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnasyrov%2Fpubsub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267822086,"owners_count":24149565,"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-07-30T02:00:09.044Z","response_time":70,"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":["emitter","pubsub","typescript"],"created_at":"2024-12-04T11:07:26.553Z","updated_at":"2025-07-30T06:31:12.691Z","avatar_url":"https://github.com/mnasyrov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple PubSub\n\n_Implements Publisher/Subscriber pattern. Provides a value emitter, subscription and consumer interface. Supports Typescript._\n\n[![npm version](https://badge.fury.io/js/%40mnasyrov%2Fpubsub.svg)](https://www.npmjs.com/@mnasyrov/pubsub)\n[![Actions Status](https://github.com/mnasyrov/pubsub/workflows/build/badge.svg)](https://github.com/mnasyrov/pubsub/actions)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\n## Usage\n\nInstall dependencies:\n\n```bash\n$ npm install --save @mnasyrov/pubsub\n```\n\nCreate an emitter and publish a value to consumers:\n\n```typescript\nimport {Emitter} from '@mnasyrov/pubsub';\n\n// Declare a value emitter.\nconst emitter = new Emitter\u003cnumber\u003e();\n\n// Subscribe by a listener.\nconst subscription = emitter.subscribe(value =\u003e {\n  console.log(value);\n});\n\n// Emit a value.\nemitter.emit(42);\n\n// Cancel a subscription.\nsubscription.unsubscribe();\n```\n\n## Public API\n\n```typescript\n/** Allows to cancel a subscription. It is compatible with RxJS/Subscription. */\nexport interface Subscription {\n  unsubscribe(): void;\n}\n\nexport type Consumer\u003cT\u003e = (value: T) =\u003e any;\n\nexport interface Publisher\u003cT\u003e {\n  subscribe(consumer: Consumer\u003cT\u003e): Subscription;\n}\n\nexport interface Emitter\u003cT\u003e {\n  constructor();\n\n  /** A number of subscribed consumers. */\n  readonly size: number;\n\n  /** Subscribes a consumer of values. */\n  subscribe(consumer: Consumer\u003cT\u003e): Subscription;\n\n  /** Emits a value to subscribed consumers. */\n  emit(value: T);\n\n  /** Removes all subscribed consumers. */\n  clear();\n}\n```\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnasyrov%2Fpubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnasyrov%2Fpubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnasyrov%2Fpubsub/lists"}