{"name":"web-worker","version":"1.0.0","description":"Consistent Web Workers in browser and Node.","main":"./cjs/node.js","browser":"./cjs/browser.js","exports":{"browser":"./cjs/browser.js","node":"./cjs/node.js","default":"./cjs/node.js"},"scripts":{"prepare":"babel node.js browser.js -d cjs","test":"eslint '*.js' test && node --experimental-modules ./node_modules/.bin/ava"},"babel":{"plugins":["@babel/plugin-syntax-dynamic-import","babel-plugin-commonjs-lite"]},"repository":{"type":"git","url":"git+https://github.com/developit/web-worker.git"},"keywords":["worker","worker_threads","webworker","web worker","web-worker","threads"],"authors":[],"license":"Apache-2.0","homepage":"https://github.com/developit/web-worker","eslintConfig":{"extends":"developit","rules":{"no-console":0}},"devDependencies":{"@babel/cli":"^7.7.7","@babel/core":"^7.7.7","@babel/plugin-syntax-dynamic-import":"^7.7.4","@babel/plugin-transform-modules-commonjs":"^7.7.5","@babel/preset-env":"^7.7.7","ava":"^2.4.0","babel-plugin-commonjs-lite":"gist:3e38560d5bed35da1fd708d635e4acb3","eslint":"^6.8.0","eslint-config-developit":"^1.1.1"},"gitHead":"d004d65c90f9e2dc6e6c3718fe64b17d408fd18e","bugs":{"url":"https://github.com/developit/web-worker/issues"},"_id":"web-worker@1.0.0","_nodeVersion":"12.16.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-BzuMqeKVkKKwHV6tJuwePFcxYMxvC97D448mXTgh/CxXAB4sRtoV26gRPN+JDxsXRR7QZyioMV9O6NzQaASf7Q==","shasum":"c7ced4e1eb6227636ada35056a9e5a477414e4d0","tarball":"http://registry-npm.ywwl.com/web-worker/download/web-worker-1.0.0.tgz","fileCount":7,"unpackedSize":29866,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJemdFjCRA9TVsSAnZWagAA5RwP/0BLCkPqVR7dheFxVvvm\n0NCqe7XrOTOKq/F206TdljMferdLYHX+UzOp/Ime5E1nxlccuIJmsBlS0YK2\nDcE+QsmIHP3gsGD8iE91jDsx5PgN2LYavRfunVliUdVvcYcKhwdhFBWdv1oR\nm0luZSpOfYPRyxeWzqsJTmaDk+kY+lZCpX2cCoYH3P7OcPap5VsgRjtlnzw6\n+g9+KFd2ZISqumF5vFPfpuWqHvjIKLvpQex98EM0u3mkT3drj9c6UD+W4H7l\nIXgxot/bRD6hQOYOH1/z5YdOrJrjdYj8fRrfmWmG7Xu4f66RP9qtXEouPltP\nCS8n2tz4IY5sSSTvRqfkY6cXX7HbRLLzpVrcPwYoDPsOH7Yt8hx+zEFbeT8v\n1AJUr2TifpSD1uAtRQJ9+H5WzCagP3QK1AYngtHyi+LCJcDa9Mi5dRoxvGsa\nY7JRJonJVJJ/kXNGH+9D4HdORSWW2qdHNTeo2O0oHPEENrKenvCUD58XzIs3\nzEKvMJ503eghQ2/YmeVcfogN1nDYTEiGI4g8CtvXKRNW9ZrbKtNhKHyOEu7M\nYtaDs2bJR4ZYEaiORohU3YouGMR5Y3/uRvWaxkd8gLaZ3h0DUTQcQRrZa7ov\n7HUXlFnOGfcVph9vWyMBob+bQRWBrxBYnKVX0MH2BJi4l9ECi/ek5KfUsDGW\nCpnw\r\n=O4Oq\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAsCuBOD/n6lgqUwqrFPiLvC7BtnltCiUN+VRkRYDvQoAiEApJ9hP4Oz0ZBm210ro9TYXM2fw4UyjBoPslE1XPAB/Yo="}],"size":8761,"noattachment":false,"key":"/web-worker/-/web-worker-1.0.0.tgz"},"maintainers":[{"email":"calvin.metcalf@gmail.com","name":"cwmma"},{"email":"jason@developit.ca","name":"developit"},{"email":"guybedford@gmail.com","name":"guybedford"}],"_npmUser":{"name":"developit","email":"jason@developit.ca"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/web-worker_1.0.0_1587138914691_0.4765174564732564"},"_hasShrinkwrap":false,"readme":"<h1 align=\"center\">\n  web-worker\n  <a href=\"https://www.npmjs.org/package/web-worker\"><img src=\"https://img.shields.io/npm/v/web-worker.svg?style=flat-square\" alt=\"npm\"></a>\n</h1>\n<p align=\"center\">\n  Native cross-platform Web Workers. Works in published npm modules.\n</p>\n<p align=\"center\">\n  <img src=\"https://user-images.githubusercontent.com/105127/79602228-1998bf00-80b8-11ea-91e4-26b212aabaa2.png\" width=\"1000\" alt=\"\">\n</p>\n\n**In Node**, it's a web-compatible Worker implementation atop Node's [worker_threads](https://nodejs.org/api/worker_threads.html).\n\n**In the browser** (and when bundled for the browser), it's simply an alias of `Worker`.\n\n### Features\n\n_Here's how this is different from worker_threads:_\n\n- makes Worker code compatible across browser and Node\n- supports Module Workers (`{type:'module'}`) natively in Node 12.8+\n- uses DOM-style events (`Event.data`, `Event.type`, etc)\n- supports event handler properties (`worker.onmessage=..`)\n- `Worker()` accepts a module URL, Blob URL or Data URL\n- emulates browser-style [WorkerGlobalScope] within the worker\n\n### Usage Example\n\nIn its simplest form:\n\n```js\nimport Worker from 'web-worker';\n\nconst worker = new Worker('data:,postMessage(\"hello\")');\nworker.onmessage = e => console.log(e.data);  // \"hello\"\n```\n\n<table>\n<thead><tr><th><strong>main.js</strong></th><th><strong>worker.js</strong></th></tr></thead>\n<tbody><tr><td>\n\n```js\nimport Worker from 'web-worker';\n\nconst url = new URL('./worker.js', import.meta.url);\nconst worker = new Worker(url);\n\nworker.addEventListener('message', e => {\n  console.log(e.data)  // \"hiya!\"\n});\n\nworker.postMessage('hello');\n```\n\n</td><td valign=\"top\">\n\n```js\naddEventListener('message', e => {\n  if (e.data === 'hello') {\n    postMessage('hiya!');\n  }\n});\n```\n\n</td></tr></tbody>\n</table>\n\n👉 Notice how `new URL('./worker.js', import.meta.url)` is used above to load the worker relative to the current module instead of the application base URL. Without this, Worker URLs are relative to a document's URL, which in Node.js is interpreted to be `process.cwd()`.\n\n> _Support for this pattern in build tools and test frameworks is still limited. We are [working on growing this](https://github.com/developit/web-worker/issues/4)._\n\n### Module Workers\n\nModule Workers are supported in Node 12.8+ using this plugin, leveraging Node's native ES Modules support.\nIn the browser, they can be used natively in Chrome 80+, or in all browsers via [worker-plugin] or [rollup-plugin-off-main-thread]. As with classic workers, there is no difference in usage between Node and the browser:\n\n<table>\n<thead><tr><th><strong>main.mjs</strong></th><th><strong>worker.mjs</strong></th></tr></thead>\n<tbody><tr><td>\n\n```js\nimport Worker from 'web-worker';\n\nconst worker = new Worker(\n  new URL('./worker.mjs', import.meta.url),\n  { type: 'module' }\n);\nworker.addEventListener('message', e => {\n  console.log(e.data)  // \"200 OK\"\n});\nworker.postMessage('https://httpstat.us/200');\n```\n\n</td><td valign=\"top\">\n\n```js\nimport fetch from 'isomorphic-fetch';\n\naddEventListener('message', async e => {\n  const url = e.data;\n  const res = await fetch(url)\n  const text = await res.text();\n  postMessage(text);\n});\n```\n\n</td></tr></tbody>\n</table>\n\n\n### Data URLs\n\nInstantiating Worker using a Data URL is supported in both module and classic workers:\n\n```js\nimport Worker from 'web-worker';\n\nconst worker = new Worker(`data:application/javascript,postMessage(42)`);\nworker.addEventListener('message', e => {\n  console.log(e.data)  // 42\n});\n```\n\n### Special Thanks\n\nThis module aims to provide a simple and forgettable piece of infrastructure,\nand as such it needed an obvious and descriptive name.\n[@calvinmetcalf](https://github.com/calvinmetcalf), who you may recognize as the author of [Lie](https://github.com/calvinmetcalf/lie) and other fine modules, gratiously offered up the name from his `web-worker` package.\nThanks Calvin!\n\n\n[worker-plugin]: https://github.com/googlechromelabs/worker-plugin\n[rollup-plugin-off-main-thread]: https://github.com/surma/rollup-plugin-off-main-thread\n[WorkerGlobalScope]: https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope\n","publish_time":1587138914873,"_cnpm_publish_time":1587138914873,"dist-tags":{"latest":"1.5.0"}}