wasm2js
Version:
Compile WebAssembly .wasm files to a commonjs module.
45 lines (26 loc) • 971 B
Markdown
# wasm2js
Compile WebAssembly .wasm files to a commonjs module.
```js
const wasm2js = require('wasm2js')
const fs = require('fs')
const wasmBuffer = fs.readFileSync('path/to/my.wasm')
const js = wasm2js(wasmBuffer)
```
## CLI
```sh
wasm2js example.wasm -o example.js
```
## Installation
npm install wasm2js
## [API](https://thlorenz.github.io/wasm2js)
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
### wasm2js
Takes a `.wasm` binary and wraps it inside a commonJS module that can be required
in Node.js and the browser.
**Parameters**
- `wasmBuf` **[Buffer](https://nodejs.org/api/buffer.html)** a buffer of the .wasm code
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the commonJS module code that wraps the wasm
## Kudos
90% of this code was extracted from @mafintosh's [wat2js](https://github.com/mafintosh/wat2js).
## License
MIT