{"_id":"@78nine/sideworker","_rev":"3-82af410ca7bb2893c9ed788a184bb0b1","name":"@78nine/sideworker","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@78nine/sideworker","version":"1.0.0","description":"SideWorker is a minimal JavaScript library to make Web Workers usage as painless as possible","main":"sideworker.js","module":"sideworker.js","unpkg":"sideworker.min.js","scripts":{"build":"rollup -c rollup.config.js","dev":"npm run build -- --watch","serve":"live-server --open=examples","prepublish":"npm run build","test":"live-server --open=tests"},"repository":{"type":"git","url":"git+https://github.com/78nine/SideWorker.git"},"keywords":[],"author":"","license":"MIT","bugs":{"url":"https://github.com/78nine/SideWorker/issues"},"homepage":"https://github.com/78nine/SideWorker#readme","devDependencies":{"live-server":"1.2.1","rollup":"2.45.2","rollup-plugin-terser":"7.0.2"},"gitHead":"7cb0688b81e369e9b63ddeedf1a1fbfe53da6de1","_id":"@78nine/sideworker@1.0.0","_nodeVersion":"14.16.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-ygHusHVblrlzd++7IjRMrajDv/abUkY+SXrvp+mPnOL7mou8HK9DcV5j9i/RzCRnRtrCMbwdV5UgA4IqX1kNXQ==","shasum":"c8429688cb20b55a23a7f0fe2f20f1c342458e24","tarball":"https://registry.npmjs.org/@78nine/sideworker/-/sideworker-1.0.0.tgz","fileCount":6,"unpackedSize":12763,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgiDqCCRA9TVsSAnZWagAAt4MQAIk3WTPImqT0aHBxxGux\nHDUFMssoGJG/6epwt/GbwK/XtU57d+SelaVaAkCbagbFGqVSs0im5Z+6Zdlf\n7zp6SR1sU5WVIkhNSKXP+6WqOaApdgQjnghQoqECWzttJtD1VuzAtHfDGM3Z\nC4kcE4e8aQNOgJNSF5qR9ZoQpgVN42J/0LxhtibpmRbh2u4JHLWdDScxtUXk\ntzKCNnOILQCkYUnUOWpz1agdfOMmNx34GivZo8/e7lSELjDE0d0ETQf3r5PY\ntJ9ZDH4VOpwx/J7qjNwblWK+vU+eDs2DrtgHEXRdZThnElPmu+qfoe0UN9Mj\niAOpJsf+KGnOzDCFJAt6As9CT7yEudMVXK0SjqZcT65nPWJSKVw+NtuRqGnu\nllXwCUgYuSSeVAxSWlOg2tRQG2ZALHAD0h/eWtU/S74ExHRe23kfckgXl8d0\nBK7REKAi4zlQ006EwDGWsLfn/1fkXXIDsbnAg4fJw4mWP6d8tPYbEkXYKpPV\ncOR0nWxjRNjfhutTi0ACcFTin6x/niPEm7gRAPy8GdwKUb3BqhIE6/6xHD/5\nMHVKh9paJ1pBrer8tw3u+J4uIOX8wSNCHGZB7/j98jlZzWs6/UZIow6GEN5p\ndKoM4/EsioEddMF7zRTKUTyCQmqgOD4dH2Hg6TKHcuAatgbpKi1GrDQWxFlr\nMS5N\r\n=q98A\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHlZ6V5YVNUV6Hl/YYEKTBtIpEIvIDSV2IDBVZeh9IfAAiEA1sRMTUTWG7ZEqiO+Ir1MqHWBXQ8aOnl0DIveW7ZMqPU="}]},"_npmUser":{"name":"tvardy","email":"tvardy@nada.ltd"},"directories":{},"maintainers":[{"name":"tvardy","email":"tvardy@nada.ltd"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sideworker_1.0.0_1619540610133_0.11916529788317742"},"_hasShrinkwrap":false},"1.0.1":{"name":"@78nine/sideworker","version":"1.0.1","description":"SideWorker is a minimal JavaScript library to make Web Workers usage as painless as possible","main":"sideworker.js","module":"sideworker.js","unpkg":"sideworker.min.js","scripts":{"build":"rollup -c rollup.config.js","dev":"npm run build -- --watch","serve":"live-server --open=examples","prepublish":"npm run build","test":"live-server --open=tests"},"repository":{"type":"git","url":"git+https://github.com/78nine/SideWorker.git"},"keywords":["web worker","worker"],"author":"","license":"MIT","bugs":{"url":"https://github.com/78nine/SideWorker/issues"},"homepage":"https://github.com/78nine/SideWorker#readme","devDependencies":{"live-server":"1.2.1","rollup":"2.45.2","rollup-plugin-terser":"7.0.2"},"gitHead":"32868f167a066b91486b1824525eed4e47b890ce","_id":"@78nine/sideworker@1.0.1","_nodeVersion":"14.16.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-y1aQfd/IZhedN3NM/IbzHtHSVLOFdY4PY0sazS/dn+9YFX49LuTlF8Kjz7ALYro5Av1/IkavnsaLyUUQdC+VSA==","shasum":"c34e3e1b7df61a8a8aa499b4a669112e00d1c2de","tarball":"https://registry.npmjs.org/@78nine/sideworker/-/sideworker-1.0.1.tgz","fileCount":6,"unpackedSize":12703,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgioruCRA9TVsSAnZWagAAYccP/iIoTjMItA9Dak4inM4U\nfvcdZE0S2bHX3/SItAu4usrvdtrCzn+6nrJveQWnFXsJuy8DaaNtTlb4MBKw\ncZUpAaTj2E+tY6eyFdzRkeI0K2b0tve4u1YfYGXXcUKJNHrZ492LXiquDn4h\nEOKFsJJ//G3N7uFOWTrn6iNYZKwzGo2pmGWWnavmzjCOoBJxSG3FgX4p5Kpw\nDF0tB51A8R2fKsZ09b5OKeubVl4qIH3lCQnzaip+0H3ySwpzus5A4IL2Zmxo\nrb3A8VNsavfqolJD5t09zz8LoUuf08U7j1IJRiXaIkEthhbK1TnDAqGsR1Qp\nTBv8aFzzRSObpegFK/36VemsII4LShS5l/plV1sSiQDgcYF6cmVj684cbbxv\nPakVcdY5awoYHe8WF6cG6NDOaKl2/Mrw2HqlAb/m9vn+EM6hvAiNdcDtn7j3\ns6GzulgDh/ebsu8Y4wUiYuilKYYHv6MAXY4sed5UmwmVXt/ORSTgXarOjX/C\npuCVQLL+LDWMBFbBlXN4gLTDApL+S2RzWwOoEeA2Qy/V57R+U0P8IzLwYQT3\nefoJIYzDQHIp0uMNgviMSC11MFVOZicqwGXNLF6QCQLhINMy2qx1XCQjBTRU\ntasbu5Y+7ALbOG/pvoPXpfA76WqG7aX8jk/ZwF+++MWFkMQogPPtgqa3SDlO\noRcH\r\n=XSkY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDJ5lFj3aOrVzEuKXxiPpBPic00iv/X0OGZmklWUOFGRAIhAIg7owE3AWnMJ/Vacd/O8EVybG3GlzglueU7JK9jS53R"}]},"_npmUser":{"name":"tvardy","email":"tvardy@nada.ltd"},"directories":{},"maintainers":[{"name":"tvardy","email":"tvardy@nada.ltd"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sideworker_1.0.1_1619692269500_0.5946175516171237"},"_hasShrinkwrap":false},"1.0.2":{"name":"@78nine/sideworker","version":"1.0.2","description":"SideWorker is a minimal JavaScript library to make Web Workers usage as painless as possible","main":"sideworker.js","module":"sideworker.js","unpkg":"sideworker.min.js","scripts":{"build":"rollup -c rollup.config.js","dev":"npm run build -- --watch","serve":"live-server --open=examples","prepublish":"npm run build","test":"live-server --open=tests"},"repository":{"type":"git","url":"git+https://github.com/78nine/SideWorker.git"},"keywords":["web worker","worker"],"author":"","license":"MIT","bugs":{"url":"https://github.com/78nine/SideWorker/issues"},"homepage":"https://github.com/78nine/SideWorker#readme","devDependencies":{"live-server":"1.2.1","rollup":"2.56.0","rollup-plugin-terser":"7.0.2"},"gitHead":"ff8268c5c0edd2a274a3fb554a66ac052e679d61","_id":"@78nine/sideworker@1.0.2","_nodeVersion":"14.17.0","_npmVersion":"7.20.3","dist":{"integrity":"sha512-6J3SviCQUSfIaofZ7I28Hzw5qXUN/hWH0cz1QrUBEwm+cFSoWyoS9txHqJnXQe60nKtCdLkFY3Y4lVHvQ0iCEw==","shasum":"65e7776e3d6d298a8db63fcd857cd7a212e282d6","tarball":"https://registry.npmjs.org/@78nine/sideworker/-/sideworker-1.0.2.tgz","fileCount":5,"unpackedSize":10183,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhC+jbCRA9TVsSAnZWagAAQfkP/ArmFIgnMsAXexbLUZtw\nzQHyRN6iCmPDtjIoCa6KcthadZobEsJMvpQL1xj4k3SSXDz6T4lNmEaf9524\nxfPI32JODsiUwaPqh3tRp9JiVlweYdoMzk/2Lq8smb/R5R90ymtp/jocYWD3\np3/36RMJCskT7LFuY6hUBevh0YdZKUZRbo7HbdQgXoGnXaANRTbaQE8Z4iJo\n/iPPeYxTMHdk/PnJzdANPjGdOv4U93AnK32bg6KQv9MFp0s8G5zlckEtuzW8\n63IbN4LHwi7KANVGS+GHhTTbRTXdPF4Vt0fqPSAW8Z0HQGqJl3o00Kg4DYpp\n+sjuX6FrUgLM6w8GERrLg1jRp+KAtz2VCiWVtg3nSZO9Vv+H/4ts8nld56nb\nGk14GqehG8VBfZCxj0yJI9ztZXElDMbb5PJXAgEiWhGPY/nPPUn4RcOA+jv7\nrSwejwTVvZXE1S3UyQuby6UPkD5GjsFkRK9W+VyPGFwwqZro/OVtovhsiWlg\n2jyb51D67F46K0JA7HqXQzyEv6fFkkcSAjKcPASmIPEjltFuGGy83bpUQ+cs\njyccwlhZtRSoD2qankOhXahZt1jiWor9doxDooPtTOtZjwwlrGs29RL9a7NZ\nH8iC6IAoMXBvFIwzjIwXBh4KZmOx3wQv4+4qplL3OstbH7cSvu88wdj7DH8j\n8SG0\r\n=Fqic\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC6GjmAo/avPuHHr3xUGP7sJpABBEbluB+zehq2n4cfnAiEAh/jwEpzzkL7OI4FLMLlK+2jpGmxqNtw52+JgOxkfOWo="}]},"_npmUser":{"name":"tvardy","email":"tvardy@nada.ltd"},"directories":{},"maintainers":[{"name":"tvardy","email":"tvardy@nada.ltd"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sideworker_1.0.2_1628170459462_0.9723718755978008"},"_hasShrinkwrap":false}},"time":{"created":"2021-04-27T16:23:29.833Z","1.0.0":"2021-04-27T16:23:30.337Z","modified":"2022-04-04T10:49:10.581Z","1.0.1":"2021-04-29T10:31:09.655Z","1.0.2":"2021-08-05T13:34:19.584Z"},"maintainers":[{"name":"tvardy","email":"tvardy@nada.ltd"}],"description":"SideWorker is a minimal JavaScript library to make Web Workers usage as painless as possible","homepage":"https://github.com/78nine/SideWorker#readme","keywords":["web worker","worker"],"repository":{"type":"git","url":"git+https://github.com/78nine/SideWorker.git"},"bugs":{"url":"https://github.com/78nine/SideWorker/issues"},"license":"MIT","readme":"# SideWorker\n\nSideWorker is a minimal JavaScript library to make using Web Workers as painless as possible.\n\nIt has been based on the [WorkerB](https://github.com/lukeschaefer/WorkerB) library by [Luke Schaefer](https://github.com/lukeschaefer).\n\nThe main purpose of SideWorker is NOT having to create a seperate file for code that is run in a different thread.\nThe Web Workers can be created inline to the main code and be communicated with asynchronously.\n\nThe idea is to consolidate the seperate script and the logic to interact with that script into one JS object.\n\n\n# Usage\n\n\n## Installation\n\nSideWorker has no dependencies. You can install it via NPM:\n\n```bash\nnpm install @79nine/SideWorker\n```\n\nand then use it in your code:\n\n```js\nimport SideWorker from '@78nine/sideworker' // ES Module style\n// or\nconst SideWorker = require('@78nine/sideworker') // Node style\n```\n\nAnother option is to simply include the [minified](./sideworker.min.js) file in your project (e.g. through the UnPKG):\n\n```html\n<script src='https://unpkg.com/@78nine/sideworker'></script>\n```\n\nThis option will expose a global `SideWorker` variable available on you web page.\n\n\n## Usage example:\n\n```js\n// Create a new, empty SideWorker\nconst worker = new SideWorker();\n\n// Define a method that will be run later in your code. This method needs:\n  //  A name -> 'countToX'\n  //  A function it will perform\n\nworker.define('countToX', (x) => {\n  for(let i = 0; i < x; i++) {\n    continue;\n  }\n  return i;\n}\n\n// Use the defined method where you need it, and handle it's result via Promise:\nworker.run.countToX(42).then((res) => console.log('X is', res));\n\n// or with async/await syntax\nconst res = await worker.run.countToX(128);\n\nconsole.log('Now the X is', res);\n\n// The method's operation is non-blocking and performed in a seperate thread.\n```\n\n## Options:\n\nWhen creating an instance of the SideWorker you can pass it and object with two options:\n\n### debug\n\n_Default: false_\n\nIf the `debug` option will be set to `true` the SideWorker will give you some additional information about it's work inside the browser's console.\n\n```js\nconst worker = new SideWorker({ debug: true });\n```\n\n### init\n\n_Default: undefined_\n\nThe `init` option can be used to pass a function, which then will be automatically called upon the Web Worker's creation.\nThis can be very useful for instance to `importScripts()` and define worker-scoped variables or function needed later.\n\n```js\nconst worker = new SideWorker({\n  init: () => {\n    importScripts('https://unpkg.com/faker@5.5.3/dist/faker.min.js');\n\n    self.someGlobalFunction = () => {\n      // do something\n    }\n  }\n});\n\n// and then inside another method:\nworker.define('doSomething', () => {\n  // `faker` is a globally available variable\n  // `someGlobalFunction()` is a globally available function\n});\n```\n\nIt is also possible to pass additional arguments to the init function that are available in your main script's scope:\n\n```js\nconst answer = 42;\nconst persona = {\n  firstName: 'Arthur',\n  lastName: 'Dent'\n}\n\nconst worker = new SideWorker({\n  init: (num, obj) => {\n    self.answer = num; // the `num` value is `42`\n    self.him = obj; // the `obj` value is `{ firstName: 'Arthur', lastName: 'Dent' }`\n  }\n}, answer, persona);\n```\n\n---\n\nNote: examples of all the basic functionality can be also explored in the [examples](./examples) folder.\n","readmeFilename":"README.md"}