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

lavats-wasm

v0.0.4

Published

lavats是一个由**typescript**写成的支持**umd**的**DSL式**的WebAssembly汇编器。

Downloads

10

Readme

lavats-wasm

lavats是一个由typescript写成的支持umdDSL式的WebAssembly汇编器。

特色

  • 支持typescript*.d.ts文件
  • 支持umd,可运行在浏览器nodejs环境下
  • 使用DSL式,可与js语言无缝衔接

支持

规范提案

支持的提案:

安装

在命令行中输入:

npm install lavats-wasm

引入

cmd

var lavatsWasm = require("lavats-wasm");

amd

require(["lavats-wasm"], function(lavatsWasm) {

})
define(["lavats-wasm"], function(lavatsWasm) {

})

es6

import * as lavatsWasm from "lavats-wasm";

<script>

<script src="./node_modules/lavats/dist/index.js"></script>
<script>

lavatsWasm

</script>

使用

生成模块

import { Module, Func, ImportExportType, data } from "lavats-wasm";

let m = new Module({
    name: "module",
    memory: [
        { name: "memory", min: 0 }
    ],
    data: [
        { name: "data", offset: 0, memoryIndex: 0, init: data.i64(10).string("test").i64(10).toBuffer() }
    ],
    table: [
        { name: "table", elementType: ElementType.funcref, min: 0 }
    ],
    element: [
        { name: "element", tableIndex: 0, offset: 0, functionIndexes: [0] }
    ],
    import: [
        { name: "test", module: "js", importName: "test", type: ImportExportType.Memory, min: 0 },
        { name: "imFunc", module: "js", importName: "imFunc", type: ImportExportType.Function }
    ],
    export: [
        { exportName: "js", type: ImportExportType.Memory, index: "test" }
    ],
    type: [
        { name: "ifBlock", params: [Type.I32], results: [] }
    ],
    global: [
        { name: "global", valueType: Type.I32, init: 0 }
    ],
    start: "start",
    function: [
        new Func({ name: "start" }),
        new Func({
            name: "func",
            params: [{ type: Type.I32, name: "p1" }],
            locals: [{ type: Type.I32, name: "l1" }],
            codes: [
                Code.block({
                    label: "block",
                    type: { results: [Type.I32] },
                    codes: [
                        Code.block({
                            label: "block2",
                            codes: [
                                Code.call("imFunc"),
                            ]
                        }),
                        Code.i32.Const(50)
                    ]
                }),
                Code.i32.Const(10),
                Code.If({
                    label: "if",
                    type: { params: [Type.I32] },
                    then: [
                        Code.drop,
                        Code.br(0)
                    ],
                    else: [
                        Code.drop
                    ]
                }),
                Code.i32.Const(10),
                Code.If({
                    else: [
                        Code.nop
                    ]
                })
            ]
        })
    ],
    custom: [
        { name: "hello", buffer: data.string("hello").toBuffer() }
    ]
});

Module转换为二进制

let buf = m.toBuffer();    // Uint8Array(297) [0, 97, 115, 109, 1, 0, 0, 0, 1, 8, 2, 96, 1, 127, 0, ....

二进制转换为Module

let newModule = Module.fromBuffer(buf);

Module转换为字符串

let wat = m.toString();

// (module $module
//     (type $ifBlock (func (param i32)))
//     (import "js" "test" (memory $test 0))
//     (import "js" "imFunc" (func $imFunc))
//     (global $global i32 (i32.const 0))
//     (memory $memory 0)
//     (data $data (i32.const 0) "\0a\00\00\00\00\00\00\00test\0a\00\00\00\00\00\00\00")
//     (table $table 0 anyfunc)
//     (elem $element (i32.const 0) 0)
//     (func $start
//     )
//     (func $func (param $p1 i32) (local $l1 i32)
//         block $block (result i32)
//             i32.const 50
//         end
//         i32.const 10
//         if $if (param i32)
//             drop
//             br 0
//         else
//             drop
//         end
//     )
//     (start $start)
//     (export "js" (memory $test))
// )

字符串转换为Module

请参考lavats-wat

模块校验

// 会返回模块是否合法的boolean
let isValidate = m.validate();

// 当校验失败时,会抛出异常
m.check();