Skip to content

Fix typos #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SYNOPSIS
# SYNOPSIS
[![NPM Package](https://img.shields.io/npm/v/wasm-json-toolkit.svg?style=flat-square)](https://www.npmjs.org/package/wasm-json-toolkit)
[![Build Status](https://img.shields.io/travis/ewasm/wasm-json-toolkit.svg?branch=master&style=flat-square)](https://travis-ci.org/ewasm/wasm-json-toolkit)
[![Coverage Status](https://img.shields.io/coveralls/ewasm/wasm-json-toolkit.svg?style=flat-square)](https://coveralls.io/r/ewasm/wasm-json-toolkit)

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

A small toolkit for converting wasm binaries into json and back.
A small toolkit for converting wasm binaries into json and back.

# INSTALL
`npm install wasm-json-toolkit`
Expand All @@ -24,8 +24,8 @@ console.log(JSON.stringify(json, null, 2))
# CLI
Install `-g` global for cli usage.

`wasm2json [FILE]` given a file containing a wasm module produces a json representation
`json2wasm [FILE]` given a file containing a json representation produces a wasm module
`wasm2json [FILE]` given a file containing a wasm module produces a json representation
`json2wasm [FILE]` given a file containing a json representation produces a wasm module

# API
# wasm2json
Expand All @@ -37,25 +37,25 @@ converts a wasm binary into a json representation
- `Buffer` - The Webassembly Binary
- `filter` - `Set` containing the name of sections to parse. If no filter is given all sections will be parsed

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**

# json2wasm

converts a json representation to a wasm binary

**Parameters**

- `Object`
- `Object`

Returns **[Buffer](https://nodejs.org/api/buffer.html)**
Returns **[Buffer](https://nodejs.org/api/buffer.html)**

# text2json

converts text to json. The only text accepted is a simple list of opcode name and immediates

**Parameters**

- `String`
- `String`

**Examples**

Expand All @@ -68,7 +68,7 @@ i64.add
const json = text2json(codeStr)
```

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**

# iterator

Expand All @@ -92,7 +92,7 @@ for (const section of it) {

[iterator.js:26-32](https://github.com/ewasm/wasm-json-toolkit/blob/e9fdd9498451b39b84c1167e78dc4aad03b055bd/iterator.js#L26-L32 "Source code on GitHub")

if the orignal wasm module was modified then this will return the modified
if the original wasm module was modified then this will return the modified
wasm module

## iterator
Expand All @@ -107,14 +107,14 @@ return {Iterator.<Section>}
[iterator.js:64-110](https://github.com/ewasm/wasm-json-toolkit/blob/e9fdd9498451b39b84c1167e78dc4aad03b055bd/iterator.js#L64-L110 "Source code on GitHub")

The section class is always internal created by the Module class. And return
through the Module's iternator
through the Module's iterator


## toJSON

[iterator.js:83-85](https://github.com/ewasm/wasm-json-toolkit/blob/e9fdd9498451b39b84c1167e78dc4aad03b055bd/iterator.js#L83-L85 "Source code on GitHub")

Parses the section and return the JSON repesentation of it
Parses the section and return the JSON representation of it
returns {Object}

## appendEntries
Expand All @@ -126,10 +126,10 @@ parent wasm module.

**Parameters**

- `entries` **Arrayy&lt;[Buffer](https://nodejs.org/api/buffer.html)>**
- `entries` **Array&lt;[Buffer](https://nodejs.org/api/buffer.html)>**


## exammple json output
## example json output

wast
```
Expand All @@ -150,7 +150,7 @@ json
```
[
{
"name": "preramble",
"name": "preamble",
"magic": [0,97,115,109],
"version": [13,0,0,0]
},
Expand Down Expand Up @@ -186,11 +186,11 @@ json
"code": [
{
"name": "get_local",
"immediaties": "0"
"immediates": "0"
},
{
"name": "get_local",
"immediaties": "1"
"immediates": "1"
},
{
"return_type": "i32",
Expand Down
6 changes: 3 additions & 3 deletions example/out.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0061736d0d00000001070160027f7f017f03020100070a010661646454776f00000a09010700200020016a0b
[
{
"name": "preramble",
"name": "preamble",
"magic": [
0,
97,
Expand Down Expand Up @@ -52,11 +52,11 @@
"code": [
{
"name": "get_local",
"immediaties": "0"
"immediates": "0"
},
{
"name": "get_local",
"immediaties": "1"
"immediates": "1"
},
{
"return_type": "i32",
Expand Down
8 changes: 4 additions & 4 deletions iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = class ModuleIterator {
}

/**
* if the orignal wasm module was modified then this will return the modified
* if the original wasm module was modified then this will return the modified
* wasm module
*/
get wasm () {
Expand Down Expand Up @@ -60,7 +60,7 @@ module.exports = class ModuleIterator {

/**
* The section class is always internal created by the Module class. And return
* through the Module's iternator
* through the Module's iterator
*/
class Section {
constructor (sectionType, section, it, index) {
Expand All @@ -78,7 +78,7 @@ class Section {
}

/**
* Parses the section and return the JSON repesentation of it
* Parses the section and return the JSON representation of it
* returns {Object}
*/
toJSON () {
Expand All @@ -88,7 +88,7 @@ class Section {
/**
* Appends an array of entries to this section. NOTE: this will modify the
* parent wasm module.
* @param {Arrayy.<Buffer>} entries
* @param {Array.<Buffer>} entries
*/
appendEntries (entries) {
this.count += entries.length
Expand Down
8 changes: 4 additions & 4 deletions json2wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const LANGUAGE_TYPES = _exports.LANGUAGE_TYPES = {
'i64': 0x7e,
'f32': 0x7d,
'f64': 0x7c,
'anyFunc': 0x70,
'anyfunc': 0x70,
'func': 0x60,
'block_type': 0x40
}
Expand Down Expand Up @@ -241,7 +241,7 @@ _exports.typeGenerators = {
*/
memory: (json, stream) => {
leb.unsigned.write(Number(json.maximum !== undefined), stream) // the flags
leb.unsigned.write(json.intial, stream)
leb.unsigned.write(json.initial, stream)

if (json.maximum !== undefined) {
leb.unsigned.write(json.maximum, stream)
Expand Down Expand Up @@ -420,15 +420,15 @@ _exports.generateSection = function (json, stream = new Stream()) {

_exports.generate = (json, stream = new Stream()) => {
const [ preamble, ...rest ] = json
_exports.generatePreramble(preamble, stream)
_exports.generatePreamble(preamble, stream)
for (let item of rest) {
_exports.generateSection(item, stream)
}

return stream
}

_exports.generatePreramble = (json, stream = new Stream()) => {
_exports.generatePreamble = (json, stream = new Stream()) => {
stream.write(json.magic)
stream.write(json.version)
return stream
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wasm-json-toolkit",
"version": "0.2.6",
"version": "0.2.7",
"description": "this convertes wasm binaries to json and json to wasm binaries",
"main": "index.js",
"scripts": {
Expand Down
Loading