String value to Worker object converter.
npm install @lopatnov/worker-from-string
<script src="https://lopatnov.github.io/worker-from-string/dist/worker-from-string.min.js"></script>
bower install worker-from-string --save
import workerFromString from 'worker-from-string';
var workerFromString = require("worker-from-string")
var workerFromString = window.workerFromString;
workerFromString(...textValues: string[]) => Worker
Example
var workerString = "self.onmessage = function onmessage(e){ postMessage('Hello ' + e.data); }";
var worker = workerFromString(workerString);
worker.onmessage = function(e) {
console.log(e.data); // expected 'Hello world' from worker after worker.postMessage('world')
};
worker.postMessage('world');
Worker Code Editor Demo: https://lopatnov.github.io/worker-from-string/
QUnit tests: https://lopatnov.github.io/worker-from-string/test/index.html
License Apache-2.0
Copyright 2019-2020 Oleksandr Lopatnov