Skip to content

A TypeScript library. It converts string value to JavaScript Worker.

License

Notifications You must be signed in to change notification settings

lopatnov/worker-from-string

@lopatnov/worker-from-string Twitter

String value to Worker object converter.

NPM version License GitHub issues GitHub forks GitHub stars GitHub top language

Patreon LinkedIn sobe.ru

npm

Install

https://nodei.co/npm/@lopatnov/worker-from-string.png?downloads=true&downloadRank=true&stars=true

npm install @lopatnov/worker-from-string

Browser

<script src="https://lopatnov.github.io/worker-from-string/dist/worker-from-string.min.js"></script>

Bower

bower install worker-from-string --save

Import package to the project

TypeScript

import workerFromString from 'worker-from-string';

JavaScript (npm package)

var workerFromString = require("worker-from-string")

JavaScript (browser)

var workerFromString = window.workerFromString;

Convert String values into Worker

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');

Demo

Worker Code Editor Demo: https://lopatnov.github.io/worker-from-string/

QUnit tests: https://lopatnov.github.io/worker-from-string/test/index.html

Rights and Agreements

License Apache-2.0

Copyright 2019-2020 Oleksandr Lopatnov