npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oraichain/wasm-json-toolkit

v1.0.24

Published

Warp implementation of wasm-json-toolkit

Downloads

718

Readme

SYNOPSIS

NPM Package Build Status Coverage Status

js-standard-style

@oraichain/wasm-json-toolkit is a fork of https://github.com/ewasm/wasm-json-toolkit which provides consistent API for Buffer object between server and client by using safe-buffer library for node and buffer for browser.

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

INSTALL

npm install @oraichain/wasm-json-toolkit

USAGE

const fs = require('fs');
const wasm2json = require('@oraichain/wasm-json-toolkit').wasm2json;

const wasm = fs.readFileSync('./test.wasm');
const json = wasm2json(wasm);

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

API

wasm2json

converts a wasm binary into a json representation

Parameters

  • 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

json2wasm

converts a json representation to a wasm binary

Parameters

  • Object

Returns Buffer

text2json

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

Parameters

  • String

Examples

const codeStr = `
i64.const 1
i64.const 2
i64.add
`;
const json = text2json(codeStr);

Returns Object

iterator

iterator.js:12-58

The Module Iterator allows for iteration over a webassembly module's sections. A section is wrapped in a section class. A section class instance allows you append entries to a given section

Examples

const it = new Iterator(wasm);
for (const section of it) {
  console.log(section.type);
  const json = section.toJSON();
}

wasm

iterator.js:26-32

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

iterator

iterator.js:38-52

Iterates through the module's sections return {Iterator.}

Section

iterator.js:64-110

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

toJSON

iterator.js:83-85

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

appendEntries

iterator.js:92-109

Appends an array of entries to this section. NOTE: this will modify the parent wasm module.

Parameters

exammple json output

wast

(module
  (func $addTwo (param i32 i32) (result i32)
    (i32.add
      (get_local 0)
      (get_local 1)))
  (export "addTwo" (func $addTwo)))

wasm

0x010661646454776f00000a09010700200020016a0b

json

[
  {
    "name": "preramble",
    "magic": [0,97,115,109],
    "version": [13,0,0,0]
  },
  {
    "name": "type",
    "entries": [
      {
        "form": "func",
        "params": ["i32","i32"],
        "return_type": "i32"
      }
    ]
  },
  {
    "name": "function",
    "entries": [0]
  },
  {
    "name": "export",
    "entries": [
      {
        "field_str": "addTwo",
        "kind": "Function",
        "index": 0
      }
    ]
  },
  {
    "name": "code",
    "entries": [
      {
        "locals": [],
        "code": [
          {
            "name": "get_local",
            "immediaties": "0"
          },
          {
            "name": "get_local",
            "immediaties": "1"
          },
          {
            "return_type": "i32",
            "name": "add"
          },
          {
            "name": "end"
          }
        ]
      }
    ]
  }
]

LICENSE

MPL-2.0