open-index/open-npm huggingface dataset:
npm package: @surma/bfwasm
Description: A non-optimizing [Brainf_ck][bf] to WebAssembly compiler. Yes, compiler. Not interpreter.
Author: Surma
Latest version: 1.2.2

# bfwasm

A non-optimizing [Brainf_ck][bf] to WebAssembly compiler. Yes, compiler. Not interpreter.

## Installation

```
npm install -g @surma/bfwasm
```

## Usage (CLI)

```
Usage: bfwasm [options]

Options:
  -o, --output <file>  File to write compiled Wasm to
  -r, --run            Run compiled Wasm (implies --asyncify)
  --mem-dump <N>       Dump the first N cells of memory after run
  --hex-output         Turn std out into hexadecimap
  --asyncify           Run Binaryen Asyncify pass
  --wasi               Use WASI for I/O
  -h, --help           output usage information
```

## Usage (API)

```js
import { compile } from "@surma/bfwasm";

const wasmBuffer = compile(`
  ++++++++++[>++++++++++++++++++++++
  >+++++++++++++++>++++++++++++++++>+
  <<<<-]>++++++.>+++++++.>++++.
`);

const decoder = new TextDecoder();
const importsObj = {
  env: {
    in() {
      /* Called when bf programm needs input */
      return 0;
    },
    out(v) {
      /* Called when bf programm has output */
      console.log(
        decoder.decode(new Uint8Array([v]), {stream: true})
      );
    }
  }
};
const {instance} = await WebAssembly.instantiate(wasmBuffer, importsObj);
instance.exports._start();
```

**compile(program, options)** compiles `program` to a WebAssembly module exporting a `"_start"` function.

Options:

- `exportMemory` (default: `true`) will export the memory as `"memory"`.
- `autoRun` (default: `false`) will declare `"_start"` as the module’s start function.
- `useWasi` (default: `false`) use [WASI core] for I/O.

---

License Apache-2.0

[bf]: http://www.muppetlabs.com/~breadbox/bf/
[wasi core]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md
npm package: @surma/rollup-plugin-comlink
Description: Use workers seamlessly
Author: Surma
Latest version: 0.4.0

# rollup-plugin-comlink

Use workers seamlessly

Workers are JavaScript’s version of threads. [Workers are important to use][when workers] as the main thread is already overloaded, especially on slower or older devices.

[`@surma/rollup-plugin-off-main-thread`][omt plugin] teaches Rollup about Workers. This plugin makes their use seamless using [Comlink].

## Usage

To avoid having to make new releases of this plugin with every release of [Comlink] or my [OMT plugin], both of these modules have been declared as peer dependencies. This means you will have to explicitely add them to your dependency list:

```
$ npm install --save @surma/rollup-plugin-comlink @surma/rollup-plugin-off-main-thread comlink
```

### Config

```js
// rollup.config.js
import comlink from "@surma/rollup-plugin-comlink";
import omt from "@surma/rollup-plugin-off-main-thread";

export default {
  input: ["src/main.js"],
  output: {
    dir: "dist",
    // You _must_ use either “amd” or “esm” as your format.
    // But note that only very few browsers have native support for
    // modules in workers.
    format: "amd",
  },
  plugins: [comlink(), omt()],
};
```

### Example

```js
// worker.js
export function doMath(a, b) {
  return a + b;
}
```

> **Note:** Importing individual exports currently does _not_ work. `comlink:` modules only have one default export.

```js
// main.js

import workerAPI from "comlink:./worker.js";

(async function () {
  const result = await workerAPI.doMath(40, 2);
  console.assert(result == 42);
})();
```

### Options

```js
{
  // ...
  plugins: [comlink(options), omt()];
}
```

- `marker`: A string that is used as a prefix to mark a worker import. Default is `comlink`.
- `useModuleWorkers`: Use module workers (requires `{format: "esm"}`).

## TypeScript

TypeScript can be taught to handle these pseudo-imports correctly and forward the types appropriately.

```ts
// main.ts
import workerAPI from "comlink:./worker.js";

console.log(await workerAPI.sayHello("surma"));
// This would fail to compile:
// console.log(await workerAPI.doesNotExit("surma"));
```

```ts
// worker.ts
export function sayHello(name: string): string {
  return `Hello ${name}!`;
}
```

```ts
// worker-modules.d.ts
declare module "comlink:./worker.js" {
  // Do *not* move this to a top-level import, as it will turn this
  // .d.ts file from an ambient module into a local module.
  const wrap: import("comlink").Remote<typeof import("./worker.js")>;
  export default wrap;
}
```

---

License Apache-2.0

[when workers]: https://surma.dev/things/when-workers
[comlink]: https://github.com/GoogleChromeLabs/comlink
[omt plugin]: https://github.com/surma/rollup-plugin-off-main-thread
npm package: @surma/rollup-plugin-off-main-thread
Description: Use Rollup with workers and ES6 modules today.
Author: Surma
Latest version: 2.2.3

# rollup-plugin-off-main-thread

Use Rollup with workers and ES6 modules _today_.

```
$ npm install --save @surma/rollup-plugin-off-main-thread
```

Workers are JavaScript’s version of threads. [Workers are important to use][when workers] as the main thread is already overloaded, especially on slower or older devices.

This plugin takes care of shimming module support in workers and allows you to use `new Worker()`.

OMT is the result of merging loadz0r and workz0r.

## Usage

I set up [a gist] to show a full setup with OMT.

### Config

```js
// rollup.config.js
import OMT from "@surma/rollup-plugin-off-main-thread";

export default {
  input: ["src/main.js"],
  output: {
    dir: "dist",
    // You _must_ use either “amd” or “esm” as your format.
    // But note that only very few browsers have native support for
    // modules in workers.
    format: "amd"
  },
  plugins: [OMT()]
};
```

### Auto bundling

In your project's code use a module-relative path via `new URL` to include a Worker:

```js
const worker = new Worker(new URL("worker.js", import.meta.url), {
  type: "module"
});
```

This will just work.

If required, the plugin also supports plain literal paths:

```js
const worker = new Worker("./worker.js", { type: "module" });
```

However, those are less portable: in Rollup they would result in module-relative
path, but if used directly in the browser, they'll be relative to the document
URL instead.

Hence, they're deprecated and `new URL` pattern is encouraged instead for portability.

### Importing workers as URLs

If your worker constructor doesn't match `workerRegexp` (see options below), you might find it easier to import the worker as a URL. In your project's code:

```js
import workerURL from "omt:./worker.js";
import paintWorkletURL from "omt:./paint-worklet.js";

const worker = new Worker(workerURL, { name: "main-worker" });
CSS.paintWorklet.addModule(paintWorkletURL);
```

`./worker.js` and `./paint-worklet.js` will be added to the output as chunks.

## Options

```js
{
  // ...
  plugins: [OMT(options)];
}
```

- `loader`: A string containing the EJS template for the amd loader. If `undefined`, OMT will use `loader.ejs`.
- `useEval`: Use `fetch()` + `eval()` to load dependencies instead of `<script>` tags and `importScripts()`. _This is not CSP compliant, but is required if you want to use dynamic imports in ServiceWorker_.
- `workerRegexp`: A RegExp to find `new Workers()` calls. The second capture group _must_ capture the provided file name without the quotes.
- `amdFunctionName`: Function name to use instead of AMD’s `define`.
- `prependLoader`: A function that determines whether the loader code should be prepended to a certain chunk. Should return true if the load is suppsoed to be prepended.
- `urlLoaderScheme`: Scheme to use when importing workers as URLs. If `undefined`, OMT will use `"omt"`.

[when workers]: https://dassur.ma/things/when-workers
[a gist]: https://gist.github.com/surma/a02db7b53eb3e7870bf539b906ff6ff6

---

License Apache-2.0