{"id":16157168,"url":"https://github.com/yeungkc/message-port-wrapper","last_synced_at":"2026-01-16T00:48:02.923Z","repository":{"id":57687467,"uuid":"479983395","full_name":"YeungKC/message-port-wrapper","owner":"YeungKC","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-18T12:04:08.000Z","size":245,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T04:26:36.446Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/YeungKC.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-10T10:27:31.000Z","updated_at":"2022-04-10T12:36:04.000Z","dependencies_parsed_at":"2024-10-04T17:11:52.957Z","dependency_job_id":"aec2cf1f-9a7d-42fc-a8b9-ba8c8a579e05","html_url":"https://github.com/YeungKC/message-port-wrapper","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YeungKC%2Fmessage-port-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YeungKC%2Fmessage-port-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YeungKC%2Fmessage-port-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YeungKC%2Fmessage-port-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YeungKC","download_url":"https://codeload.github.com/YeungKC/message-port-wrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246892847,"owners_count":20850850,"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-10T01:48:35.694Z","updated_at":"2026-01-16T00:48:02.868Z","avatar_url":"https://github.com/YeungKC.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MessagePort\n\n\u003e Simplified IPC communication for MessagePort.\n\n## Installation\n\n```shell\nnpm install message-port\n```\n\n## Usage\n\n```typescript\nconst wrapper1 = MessagePortWrapper(port1);\nconst wrapper2 = MessagePortWrapper(port2);\n\nwrapper1.on('test', () =\u003e 'foo');\nwrapper2.on('test', (data: any) =\u003e data);\n\n\nconst data1 = await wrapper1\u003cstring\u003e('test', 'test'); // 'foo'\nconst data2 = await wrapper2.call('test', 'test'); // 'test'\n```\n\n## API\n\n```typescript\ninterface CallFunc {\n  /**\n   * invoke a handler with return value\n   */\n  \u003cR = any, T = any\u003e(channel: string, data: T): Promise\u003cR\u003e;\n}\n\nexport interface MessagePortWrapper extends CallFunc {\n  /**\n   * invoke a handler without return value\n   */\n  send: \u003cT = any\u003e(channel: string, data: T) =\u003e void;\n  invoke: CallFunc;\n  /**\n   * add a handler\n   */\n  on: \u003cT = any, R = any\u003e(channel: string, handler: InvokeHandler\u003cT, R\u003e) =\u003e void;\n  /**\n   * add a handler with once\n   */\n  once: \u003cT = any, R = any\u003e(\n    channel: string,\n    handler: InvokeHandler\u003cT, R\u003e\n  ) =\u003e void;\n  /**\n   * remove a handler\n   */\n  removeHandler: (channel: string) =\u003e void;\n  /**\n   * remove all handlers\n   */\n  removeAllHandlers: () =\u003e void;\n}\n```\n\n## Jest\n\nJest tests are set up to run with `npm test` or `yarn test`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeungkc%2Fmessage-port-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeungkc%2Fmessage-port-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeungkc%2Fmessage-port-wrapper/lists"}