{"_id":"isoworker","_rev":"357451","name":"isoworker","description":"Isomorphic workerization with dependencies","dist-tags":{"latest":"0.2.4"},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"time":{"modified":"2021-07-13T08:37:34.000Z","created":"2021-01-10T22:02:53.446Z","0.2.4":"2021-03-21T12:02:05.437Z","0.2.3":"2021-03-17T07:13:21.928Z","0.2.1":"2021-03-17T00:39:13.397Z","0.2.0":"2021-03-17T00:07:11.282Z","0.1.3":"2021-03-10T00:32:57.468Z","0.1.2":"2021-03-10T00:25:47.013Z","0.1.1":"2021-01-19T18:24:41.368Z","0.1.0":"2021-01-12T06:24:58.012Z","0.0.1":"2021-01-10T22:02:53.446Z"},"users":{},"author":{"name":"Arjun Barrett"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"versions":{"0.2.4":{"name":"isoworker","version":"0.2.4","description":"Isomorphic workerization with dependencies","main":"./lib/index.cjs","module":"./esm/browser.js","browser":{"./lib/node-worker.cjs":"./lib/worker.cjs","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.cjs","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.cjs"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.cjs"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && yarn build:lib","build:lib":"tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"eaffb096b7bf5f04531951884f95578fecfa3bdd","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.2.4","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"0106292b8c0ad35409d4bb5f78a66066db25827e","size":12552,"noattachment":false,"key":"/isoworker/-/isoworker-0.2.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.2.4.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.2.4_1616328125278_0.32042320842614624"},"_hasShrinkwrap":false,"publish_time":1616328125437,"_cnpm_publish_time":1616328125437},"0.2.3":{"name":"isoworker","version":"0.2.3","description":"Isomorphic workerization with dependencies","main":"./lib/index.cjs","module":"./esm/browser.js","browser":{"./lib/node-worker.cjs":"./lib/worker.cjs","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.cjs","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.cjs"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.cjs"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && yarn build:lib","build:lib":"tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"9be98050d448ceb51d200cbcd75b520156f541ad","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.2.3","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"c4f9f22543bcfd9e2eecbca9534daf1dd4fc2f4b","size":11168,"noattachment":false,"key":"/isoworker/-/isoworker-0.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.2.3.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.2.3_1615965201731_0.4920248525745956"},"_hasShrinkwrap":false,"publish_time":1615965201928,"_cnpm_publish_time":1615965201928},"0.2.1":{"name":"isoworker","version":"0.2.1","description":"Isomorphic workerization with dependencies","main":"./lib/index.cjs","module":"./esm/browser.js","browser":{"./lib/node-worker.cjs":"./lib/worker.cjs","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.cjs","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.cjs"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.cjs"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && yarn build:lib","build:lib":"tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"e8faff30acce0356c22acbfab29416e0a9660757","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.2.1","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"c3d232fbca18f2a12fc9381ee0d8c146e140d13d","size":9957,"noattachment":false,"key":"/isoworker/-/isoworker-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.2.1.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.2.1_1615941553161_0.4191077842814732"},"_hasShrinkwrap":false,"publish_time":1615941553397,"_cnpm_publish_time":1615941553397},"0.2.0":{"name":"isoworker","version":"0.2.0","description":"Isomorphic workerization with dependencies","main":"./lib/index.cjs","module":"./esm/browser.js","browser":{"./lib/node-worker.cjs":"./lib/worker.cjs","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.cjs","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.cjs"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.cjs"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && yarn build:lib","build:lib":"tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"60dd5f859807961329dd52cbb7ea8c72a15d6feb","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.2.0","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"023242a1cea96bbbd72e8f554afc1421c4977877","size":9878,"noattachment":false,"key":"/isoworker/-/isoworker-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.2.0.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.2.0_1615939631164_0.8082704523040241"},"_hasShrinkwrap":false,"publish_time":1615939631282,"_cnpm_publish_time":1615939631282},"0.1.3":{"name":"isoworker","version":"0.1.3","description":"Isomorphic workerization with dependencies","main":"./lib/index.cjs","module":"./esm/browser.js","browser":{"./lib/node-worker.cjs":"./lib/worker.cjs","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.cjs","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.cjs"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.cjs"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"6b9cf7d1c0d8113a2360415feed0c71392498dd2","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.1.3","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"a54587fa1da2f57d401565f83b1c4ee8b21ae372","size":7089,"noattachment":false,"key":"/isoworker/-/isoworker-0.1.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.1.3.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.1.3_1615336377293_0.9688260756979139"},"_hasShrinkwrap":false,"publish_time":1615336377468,"_cnpm_publish_time":1615336377468},"0.1.2":{"name":"isoworker","version":"0.1.2","description":"Isomorphic workerization with dependencies","main":"./lib/index.js","module":"./esm/browser.js","browser":{"./lib/node-worker.js":"./lib/worker.js","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.js","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.js"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.js"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"7bf9aa2fac5e0a5ceff9dfc09ac3983417a73153","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.1.2","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"5c6c30582d44f20d558c8f9a367e273db5842cf5","size":7107,"noattachment":false,"key":"/isoworker/-/isoworker-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.1.2.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.1.2_1615335946871_0.11688278794156437"},"_hasShrinkwrap":false,"publish_time":1615335947013,"_cnpm_publish_time":1615335947013},"0.1.1":{"name":"isoworker","version":"0.1.1","description":"Isomorphic workerization with dependencies","main":"./lib/index.js","module":"./esm/browser.js","browser":{"./lib/node-worker.js":"./lib/worker.js","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.js","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.js"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.js"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"62c0a9f3c38e02746207f4a094e60da684833545","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.1.1","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"99e68e08c18300685695c5187c4adbffa14d254b","size":6922,"noattachment":false,"key":"/isoworker/-/isoworker-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.1.1.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.1.1_1611080681193_0.21047034138372012"},"_hasShrinkwrap":false,"publish_time":1611080681368,"_cnpm_publish_time":1611080681368},"0.1.0":{"name":"isoworker","version":"0.1.0","description":"Isomorphic workerization with dependencies","main":"./lib/index.js","module":"./esm/browser.js","browser":{"./lib/node-worker.js":"./lib/worker.js","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.js","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.js"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.js"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"d23dc052ca1bc1ce8b49a83477fa181ac56ee749","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.1.0","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"7100e5cf54df7b47f16c0837b6d710c91e5070a3","size":6902,"noattachment":false,"key":"/isoworker/-/isoworker-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.1.0.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.1.0_1610432697836_0.6286303298690159"},"_hasShrinkwrap":false,"publish_time":1610432698012,"_cnpm_publish_time":1610432698012},"0.0.1":{"name":"isoworker","version":"0.0.1","description":"Isomorphic workerization with dependencies","main":"./lib/index.js","module":"./esm/browser.js","browser":{"./lib/node-worker.js":"./lib/worker.js","./esm/index.mjs":"./esm/browser.js"},"exports":{".":{"node":"./esm/index.mjs","require":"./lib/index.js","default":"./esm/browser.js"},"./node":{"import":"./esm/index.mjs","require":"./lib/node.js"},"./browser":{"import":"./esm/browser.js","require":"./lib/browser.js"}},"types":"lib/index.d.ts","author":{"name":"Arjun Barrett"},"license":"MIT","scripts":{"build":"yarn lint && tsc && tsc --project tsconfig.esm.json && node -r ts-node/register scripts/rewriteBuilds.ts","lint":"eslint --fix \"src/**/*.ts\"","prepack":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/101arrowz/isoworker.git"},"bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"keywords":["worker","workerize","isomorphic","inline"],"devDependencies":{"@types/node":"^14.14.11","@typescript-eslint/eslint-plugin":"^4.9.1","@typescript-eslint/parser":"^4.9.1","eslint":"^6.8.0","eslint-config-prettier":"^6.9.0","eslint-plugin-prettier":"^3.1.2","prettier":"^1.19.1","ts-node":"^9.1.1","typescript":"^4.1.2"},"gitHead":"296d12e69057c3d1fb4dc47ee31c5b865d6518a3","homepage":"https://github.com/101arrowz/isoworker#readme","_id":"isoworker@0.0.1","_nodeVersion":"14.7.0","_npmVersion":"6.14.7","dist":{"shasum":"c98cf41ef8ebe217e56ffadecb69cf11d8b93423","size":6615,"noattachment":false,"key":"/isoworker/-/isoworker-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/isoworker/download/isoworker-0.0.1.tgz"},"_npmUser":{"name":"101arrowz","email":"arjunbarrett@gmail.com"},"directories":{},"maintainers":[{"name":"101arrowz","email":"arjunbarrett@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isoworker_0.0.1_1610316173338_0.7103056388019553"},"_hasShrinkwrap":false,"publish_time":1610316173446,"_cnpm_publish_time":1610316173446}},"readme":"# isoworker\n\nIsomorphic workerization with context in 6kB\n\n## Why?\n\nWorker threads allow you to run code without blocking the event loop or slowing down your browser. They can be used for hard number-crunching, running WASM without freezing the browser, parallel processing, and many more cool possibilities.\n\nIf you're not experienced with build tools or are creating a library, however, using worker threads is virtually impossible. Nothing works on all platforms, with all build tools, and doesn't require embedding the codebase as a string. Moreover, it's not possible to transfer data, particularly complex classes and objects, to the worker thread without using JSON. That's why most \"asynchronous\" packages such as [JSZip](https://github.com/Stuk/jszip) still run on the main thread in an event loop. While running in the event loop is fine, it doesn't allow your code to take advantage of the multiple CPU cores that exist on most devices; everything still runs on one thread.\n\nIn just 6kB of pure JavaScript (3kB gzipped), `isoworker` abstracts all these difficulties away by making your standard functions magically run in a separate thread in all environments. You don't even need a new file to run your code, and unlike other workerization packages, you can actually call other functions and use variables from your worker. The serializer is the heart of the package;\n\nA subset of this package is used in [`fflate`](https://github.com/101arrowz/fflate), the fastest compression library for JavaScript. It's been immensely useful for supporting Node.js and browsers as old as IE11 while still offering *true* parallelization potential.\n\n## Usage\n\nInstall:\n```sh\nnpm i isoworker # or yarn add isoworker, or pnpm add isoworker\n```\n\nImport:\n```js\nimport { workerize } from 'isoworker';\n```\n\nIf your environment doesn't support ES Modules (e.g. Node.js):\n```js\nconst { workerize }  = require('isoworker');\n```\n\nIf your environment doesn't support bundling:\n```js\n// For the browser:\nimport { workerize } from 'isoworker/esm/browser.js';\n// If for some reason the standard ESM import fails on Node:\nimport { workerize } from 'isoworker/esm/index.mjs';\n```\n\nUMD build (for CDN support) coming soon.\n\nAnd use:\n```js\nlet number = 0;\nconst count = () => {\n  console.log(number);\n  return number++;\n};\n\nconst asyncCount = workerize(\n  // The function to workerize\n  count,\n  // The dependency list, i.e. any variables or functions you want to use\n  // You must use a function that returns an array of dependencies\n  () => [number]\n);\n\n// This function is now asynchronous and accepts a callback\nasyncCount((err, result) => {\n  console.log(`got ${result} from worker`);\n});\n// 0\n// got 0 from worker\nasyncCount(() => {});\n// 1\n\n// Since that was run on another thread, the main thread's value hasn't\n// been mutated\nconsole.log(number); // 0\n\n// When you're finished using the function, call .close() to free the\n// resources used by the worker thread\nasyncCount.close();\n```\n\nIf you want to run setup code, you can use a condition within the function and/or a flag.\n```js\nconst wasm = {};\n\n// generic WASM runner\n// Promises are automatically resolved, so using async/await is fine\nconst runWasmMainThread = async (wasmName, method, ...args) => {\n  // The wasm object acts as a cache for WASM files\n  if (!wasm[wasmName]) {\n    wasm[wasmName] = (await WebAssembly.instantiateStreaming(\n      fetch(`/wasm-files/${wasmName}.wasm`)\n    )).module.exports;\n  }\n  return wasm[wasmName][method](...args);\n}\nconst runWasm = workerize(runWasmMainThread, () => [wasm]);\n\n// If /wasm-files/hello.wasm exports a sayHelloTo method\n// that accepts a string argument for who to say hello to:\nrunWasm('hello', 'sayHelloTo', 'me', (err, res) => {\n  console.log(res); // Hello me!\n});\n\n// This all runs on a separate thread; WASM is not here\nconsole.log(wasm); // undefined\n```\n\nThe workerizer supports complex types (including symbols, functions, classes, and instances of those classes) with infinite nesting thanks to a nifty recursive serializer.\n\n```js\n// ES5 style class works\nfunction Example1() {\n  this.y = 2;\n}\nExample1.prototype.z = function() {\n  return this.y * 2;\n}\n\nfunction Example2() {\n  this.x = 3;\n  Example1.call(this);\n}\n// Prototypal inheritance/extension works\nExample2.prototype = Object.create(Example1.prototype);\n\n// Normal extension works as well\nclass OtherClass extends Example2 {\n  constructor() {\n    super();\n    console.log('Created an OtherClass');\n  }\n\n  getResult() {\n    return 'z() = ' + this.z();\n  }\n}\n\nconst dat = new OtherClass(); // Created an OtherClass\n\nconst getZ = workerize(() => {\n  // On the worker thread, now dat.y is increased by dat.x\n  dat.y += dat.x;\n  return dat.getResult();\n}, () => [dat]);\n\n\n// Note than when doing this, \"Created an OtherClass\" is not logged\n// Your classes and objects are created without construction or mutation\n\ngetZ((err, result) => console.log(result)) // z() = 10\ngetZ((err, result) => console.log(result)) // z() = 16\n\n// Nothing changed on the main thread\nconsole.log(dat.y) // 2\nconsole.log(dat.getResult()); // z() = 4\n```\n\nIf you need to maximize performance and know how to use [Transferables](https://developer.mozilla.org/en-US/docs/Web/API/Transferable), you can set a list of transferables by returning `__transfer` in your workerized function.\n\n```js\n// Since Uint8Array and Math.random() are in the global environment,\n// they don't need to be added to the dependency list\nconst getRandomBuffer = workerize((bufLen) => {\n  if (bufLen > 2 ** 30) {\n    throw new TypeError('cannot create over 1GB random values');\n  }\n  const buf = new Uint8Array(bufLen);\n  for (let i = 0; i < bufLen; ++i) {\n    // Uint8Array automatically takes the floor\n    buf[i] = Math.random() * 256;\n  }\n  buf.__transfer = [buf.buffer];\n  return buf;\n}, () => []);\ngetRandomBuffer(2 ** 28, (err, result) => {\n  console.log(err); // null\n  console.log(result); // Uint8Array(268435456) [ ... ]\n});\ngetRandomBuffer(2 ** 31, (err, result) => {\n  console.log(err); // TypeError: cannot process over 1GB\n  console.log(result); // null\n});\n```\n\nIf you're a library author, you may want to use the context creation API but don't need the workerization support. In that case, use `createContext(() => [dep1, dep2])` and use the return value `[code, initMessage, transferList]`. Take a look at the source code to understand how to use these. Effectively, `code` encodes most of the dependencies, `initMessage` contains code to be executed on the first message (and occasionally values that must be passed to that code), and `transferList` is the array of `Transferable`s that can optionally be transferred in the initialization message for much better initialization performance at the cost of breaking the implementation on the main thread if it depends on values that were transferred.\n\n## Possible Pitfalls\n\nOne important issue to note is that `isoworker` does NOT serialize the data passed into and out of your functions by default, meaning that custom classes and objects cannot be used as parameters or return values. If you want to use complex arguments, you can use `true` as the third parameter to the `workerize` function.\n\n```js\nclass CustomClass {\n  static Y = 10;\n  x = 1;\n  constructor(y = 2) {\n    this.y = y;\n  }\n  getX() {\n    return this.x;\n  }\n}\n\n// The dependency list can be [CustomClass] or [CustomClass.Y]\n// With [CustomClass.Y], the worker may initialize more quickly.\nconst diffStaticYWithXY = workerize(obj => {\n  return CustomClass.Y - obj.getX() * obj.y;\n}, () => [CustomClass.Y], true); // <-- third argument is true\n\n// Now, custom classes work in arguments\ndiffStaticYWithXY(new CustomClass(), (err, res) => {\n  console.log(res); // 8\n});\n\nconst cc2 = new CustomClass(3);\ncc2.x = 4;\ndiffStaticYWithXY(cc2, (err, res) => {\n  console.log(res); // -2\n});\n```\n\nThis isn't the default behavior because it's expensive performance-wise and because dynamic evaluation can break on sites with a tight Content Security Protocol. In addition, note that the return value may never be something that cannot be structured-cloned (besides `Promise`, which is automatically resolved).\n\nAlthough `isoworker` can handle most dependencies, including objects of user-created classes, certain native classes and objects will not work. Of course, the basic ones (primitives, dates, objects, arrays, sets, maps, etc.) work well, but more advanced types such as `MediaRecorder` and `Audio` cannot be used as dependencies. You'll need to send over information that you used to construct them (for `Audio`, the URL) via function parameters. Additionally, any custom class using a private field (denoted by a `#` prefix, e.g. `#someKey`) will not have access to the private field post-workerization because finding the value for that field at runtime is not possible.\n\nAnother point to note is that much of the package is based off of elaborate (but fallible) pseudo-parsers for stringified functions. In other words, if you try to break things, you can. However, as long as you don't do something like this:\n\n```js\nconst dontDoThis = {\n  get [\"(please)\"] /* function() { */ () {\n    console.log('hi')\n  }\n};\nworkerize(() => dontDoThis[\"(please)\"], () => [dontDoThis]);\n```\n\nyou will be fine.\n\n## License\nMIT","_attachments":{},"homepage":"https://github.com/101arrowz/isoworker#readme","bugs":{"url":"https://github.com/101arrowz/isoworker/issues","email":"arjunbarrett@gmail.com"},"license":"MIT"}