{"id":29175900,"url":"https://github.com/oneislandearth/worker-module","last_synced_at":"2025-08-24T14:14:20.972Z","repository":{"id":57133194,"uuid":"332431750","full_name":"oneislandearth/worker-module","owner":"oneislandearth","description":"A simpler way of creating WebWorkers for any application","archived":false,"fork":false,"pushed_at":"2021-02-10T01:26:35.000Z","size":163,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-28T14:43:34.243Z","etag":null,"topics":["webworkers","workers"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oneislandearth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-24T11:27:23.000Z","updated_at":"2021-02-10T01:24:49.000Z","dependencies_parsed_at":"2022-09-03T15:02:01.677Z","dependency_job_id":null,"html_url":"https://github.com/oneislandearth/worker-module","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/oneislandearth/worker-module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneislandearth%2Fworker-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneislandearth%2Fworker-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneislandearth%2Fworker-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneislandearth%2Fworker-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oneislandearth","download_url":"https://codeload.github.com/oneislandearth/worker-module/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oneislandearth%2Fworker-module/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264487020,"owners_count":23616183,"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":["webworkers","workers"],"created_at":"2025-07-01T16:12:00.660Z","updated_at":"2025-07-22T18:33:48.115Z","avatar_url":"https://github.com/oneislandearth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @oneisland/worker-module\n\nA simpler way of creating WebWorkers for any application\n\n## Overview\n\nDesigned to make the process of creating applications using WebWorkers much easier when communicating between the main frame and the WebWorkers\n\nIt's time to say no more to `onmessage` and `postmessage` events and generate useful WebWorkers with ease\n\nSimply [define your worker class](#defining-a-worker-with-workermodule) by extending `WorkerModule` and compile using the [webpack loader](#webpack-configuration)\n\nYou'll be able to [interact with your worker](#using-a-worker-from-within-an-app) as if it were any other class instantiation from within your application\n\n## Installation\n\nInstall the package via npm\n\n```bash\nnpm install @oneisland/worker-module\n```\n\n## Usage\n\n### Defining a worker with WorkerModule\n\nSee [example/src/sqrt.worker.js](https://github.com/oneislandearth/worker-module/blob/main/example/src/sqrt.worker.js)\n\n```js\n// Import the worker module\nimport { WorkerModule } from '@oneisland/worker-module';\n\n// Create a worker to solve square roots\nexport class SquareRootWorker extends WorkerModule {\n  \n  // Instantiate as a WorkerModule\n  constructor() { super() }\n\n  // Perform a calculation\n  calculate(number) {\n    return Math.sqrt(number).toFixed(2);\n  }\n}\n```\n\n### Using a worker from within an app\n\nSee [example/src/app.js](https://github.com/oneislandearth/worker-module/blob/main/example/src/app.js)\n\n```js\n// Import the worker\nimport { SquareRootWorker } from './sqrt.worker';\n\n// Create an instance of the worker\nconst sqrt = new SquareRootWorker();\n\n// Define the computation event\nconst render = async({ target }) =\u003e {\n\n  // Compute the results\n  const result = await sqrt.calculate(target.value);\n  \n  // Update the result\n  document.querySelector('#output').innerHTML = `${result}\u003cbr\u003e(rounded)`;\n};\n\n// Set the value to a random value\ndocument.querySelector('#input').value = Math.floor(Math.random() * 10000 + 1)\n\n// Bind the event listener\ndocument.querySelector('#input').addEventListener('input', render);\n\n// Trigger a rendering\ndocument.querySelector('#input').dispatchEvent(new Event('input'));\n```\n\n### Webpack configuration\n\nSee [example/webpack.config.js](https://github.com/oneislandearth/worker-module/blob/main/example/webpack.config.js)\n\n```js\n// Webpack rules for building\nmodule.exports = {\n  entry: `${__dirname}/src/app.js`,\n  output: {\n    publicPath: `/`,\n    path: `${__dirname}/dist/`,\n    filename: `app.js`,\n  },\n  module: {\n    rules: [{\n      test: /(.*)(?:worker\\.js)$/,\n      loader: `@oneisland/worker-module/loader`,\n      options: {\n        publicPath: `/`,\n        path: `${__dirname}/dist/`,\n        filename: `[name].js`\n      }\n    }]\n  },\n  devServer: {\n    contentBase: `${__dirname}/dist/`,\n    compress: true,\n    port: 8080\n  }\n};\n```\n\n### More details\n\nSee the [example directory](https://github.com/oneislandearth/worker-module/tree/main/example) for further information","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foneislandearth%2Fworker-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foneislandearth%2Fworker-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foneislandearth%2Fworker-module/lists"}