{"id":13625636,"url":"https://github.com/egoist/typed-worker","last_synced_at":"2025-07-28T16:07:18.133Z","repository":{"id":56750988,"uuid":"524458406","full_name":"egoist/typed-worker","owner":"egoist","description":"Type-safe and Promisified API for Web Worker and Iframe","archived":false,"fork":false,"pushed_at":"2024-01-17T15:20:14.000Z","size":35,"stargazers_count":194,"open_issues_count":1,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-07T05:41:57.324Z","etag":null,"topics":[],"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/egoist.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},"funding":{"github":"egoist"}},"created_at":"2022-08-13T17:00:20.000Z","updated_at":"2024-11-23T16:11:55.000Z","dependencies_parsed_at":"2024-02-17T19:48:58.999Z","dependency_job_id":null,"html_url":"https://github.com/egoist/typed-worker","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"egoist/ts-lib-starter","purl":"pkg:github/egoist/typed-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Ftyped-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Ftyped-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Ftyped-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Ftyped-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/typed-worker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Ftyped-worker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267543269,"owners_count":24104538,"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-28T02:00:09.689Z","response_time":68,"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":[],"created_at":"2024-08-01T21:01:58.621Z","updated_at":"2025-07-28T16:07:18.098Z","avatar_url":"https://github.com/egoist.png","language":"TypeScript","funding_links":["https://github.com/sponsors/egoist","https://github.com/sponsors/egoist)."],"categories":["others","TypeScript"],"sub_categories":[],"readme":"**💛 You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/egoist).**\n\n---\n\n# typed-worker\n\n[![npm version](https://badgen.net/npm/v/typed-worker)](https://npm.im/typed-worker) [![npm downloads](https://badgen.net/npm/dm/typed-worker)](https://npm.im/typed-worker) [![paka type docs](https://badgen.net/badge/typedoc/typed-worker/pink)](https://paka.dev/npm/typed-worker)\n\n## Install\n\n```bash\nnpm i typed-worker\n```\n\n## Usage\n\nCreate a `worker.ts`:\n\n```ts\nimport { handleActions } from \"typed-worker\"\n\nexport const actions = {\n  async sum(a: number, b: number) {\n    await someHeavyOperation()\n    return a + b\n  },\n}\n\nexport type Actions = typeof actions\n\nhandleActions(actions)\n```\n\nIn your `app.ts` where you want to use the worker:\n\n```ts\nimport { createWorker } from \"typed-worker\"\nimport { type Actions } from \"./worker\"\n\nconst worker = createWorker\u003cActions\u003e(\n  // Require a bundler like Vite, webpack etc\n  () =\u003e\n    new Worker(new URL(\"./worker.ts\", import.meta.url), {\n      type: \"module\",\n    }),\n)\n\nconst result = await worker.run(\"sum\", 1, 2)\n\nexpect(result).toBe(3)\n```\n\nTo use the `worker.ts` in an iframe instead of a web worker, you only need to return the `iframe` element in `createWorker` instead:\n\n```ts\nconst iframe = createWorker\u003cActions\u003e(\n  () =\u003e document.querySelector\u003cHTMLIframeElement\u003e(\"#your-iframe-element\")!,\n)\n\nconst result = await iframe.run(\"sum\", 1, 2)\n```\n\n### Error handling\n\nErrors thrown in the worker will be re-thrown when you call the `.run` method:\n\n```ts\nworker.run(\"some-problematic-action\").catch((err) =\u003e {\n  // err is the error thrown in the worker\n})\n```\n\n## Sponsors\n\n[![sponsors](https://sponsors-images.egoist.dev/sponsors.svg)](https://github.com/sponsors/egoist)\n\n## License\n\nMIT \u0026copy; [EGOIST](https://github.com/sponsors/egoist)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Ftyped-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Ftyped-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Ftyped-worker/lists"}