Skip to content

@lopatnov/worker-from-string

Latest
Compare
Choose a tag to compare
@lopatnov lopatnov released this 29 Aug 23:55
· 4 commits to master since this release

@lopatnov/worker-from-string

String value to Worker object converter.

NPM version
License
Libraries.io dependency status for latest release
GitHub issues
GitHub forks
GitHub stars
GitHub top language

Patreon
LinkedIn
Twitter

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

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

Rights and Agreements

License Apache-2.0

Copyright 2019-2020 Oleksandr Lopatnov