Socket
Book a DemoInstallSign in
Socket

js-inline-wat

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-inline-wat

A tool for bundling a WebAssembly .wat file into a .js library file.

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

js-inline-wat npm version

A tool for bundling a WebAssembly .wat file into a .js ES6 library file.

Installation

npm install -D js-inline-wat

Usage

$ inlinewat sample.wat [-o sample.wat.js] [-t decoded]

In package.json

scripts: {
    "inlinewat": "inlinewat wat/sample.wat -o build/sample.js"
}

Options

  • --input file The .wat file to inline

  • -o, --output file The .js file to create

  • -t, --type typeName The type of JavaScript file to generate - "decoded" (default), "encoded", "fetch"

  • -h, --help Show this Help page

Types

Each type outputs a different variant of JavaScript file

-type fetch

Creates a JavaScript file with a default export function that can be used anywhere you could use fetch(). e.g.

import fetchSample from 'sample'; // sample.js contains the bundled .wat

WebAssembly.instantiateStreaming(fetchSample)
    .then(obj => obj.instance.exports.exported_func());

-type decoded

Creates a JavaScript file with a default export byte array containing the decoded .wat content

Note: You'll probably want to use WebAssembly.instantiateStreaming() in most cases, as it is more efficient than instantiate().

import decodedSample from 'sample'; // sample.js contains the bundled .wat

WebAssembly.instantiate(decodedSample)
    .then(obj => obj.instance.exports.exported_func());

-type encoded

Creates a JavaScript file with a default export string value containing the base64 encoded .wat file

import encodedSample from 'sample'; // sample.js contains the bundled .wat

// Decode the base64 string then compile...

Keywords

webassembly

FAQs

Package last updated on 08 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts