Skip to content

Instantly share code, notes, and snippets.

@Jonarod
Jonarod / blob_conversions_util.js
Created December 7, 2019 04:56
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based.
const BlobToBase64 = function(blob){
let blobUrl = URL.createObjectURL(blob);
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = err => reject(err);
img.src = blobUrl;
}).then(img => {
URL.revokeObjectURL(blobUrl);
@julianpoemp
julianpoemp / inline-web-worker-typescript.md
Last active March 4, 2024 10:52
Easy inline web worker with Typescript

Easy web worker with Typescript

This code makes use of two classes: TsWorker and TsWorkerJob. TsWorker initializes an inline worker and runs one job. The TsWorker class needs to be initialized with a function and the function's arguments as an array.

Example:

 const tsWorker = new TsWorker();

 // create a new job. You can create a sub class of TsWorker so that you don't have to add the function any time.