@wasmgroundup/emit 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +30 -0
  2. package/index.d.ts +1 -1
  3. package/package.json +5 -1
package/README.md CHANGED
@@ -10,6 +10,36 @@ A JavaScript library to emit WebAssembly 1.0 binary modules.
10
10
  npm i @wasmgroundup/emit
11
11
  ```
12
12
 
13
+ ## Example
14
+
15
+ Build a WebAssembly module with an exported `add` function:
16
+
17
+ ```typescript
18
+ import * as w from "@wasmgroundup/emit";
19
+
20
+ const mod = w.module([
21
+ w.typesec([w.functype([w.valtype.i32, w.valtype.i32], [w.valtype.i32])]),
22
+ w.funcsec([w.typeidx(0)]),
23
+ w.exportsec([w.export_("add", w.exportdesc.func(w.funcidx(0)))]),
24
+ w.codesec([
25
+ w.code(
26
+ w.func(
27
+ [],
28
+ w.expr([
29
+ [w.instr.local.get, ...w.i32(0)],
30
+ [w.instr.local.get, ...w.i32(1)],
31
+ w.instr.i32.add,
32
+ ]),
33
+ ),
34
+ ),
35
+ ]),
36
+ ]);
37
+
38
+ const { instance } = await WebAssembly.instantiate(w.flatten(mod));
39
+ const { add } = instance.exports as { add: (a: number, b: number) => number };
40
+ console.log(add(1, 2)); // 3
41
+ ```
42
+
13
43
  ## Features
14
44
 
15
45
  - Simple API following the [spec](https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/)'s naming conventions
package/index.d.ts CHANGED
@@ -92,7 +92,7 @@ export function code(func: Fragment): Fragment;
92
92
 
93
93
  export function func(locals: readonly Fragment[], body: Fragment): Fragment;
94
94
 
95
- export function expr(instrs: readonly Fragment[]): Fragment;
95
+ export function expr(instrs: Fragment): Fragment;
96
96
 
97
97
  export function codesec(codes: readonly Fragment[]): Fragment;
98
98
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wasmgroundup/emit",
3
3
  "description": "A library for creating binary-encoded WebAssembly modules",
4
- "version": "2.1.0",
4
+ "version": "2.1.1",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
@@ -30,13 +30,17 @@
30
30
  },
31
31
  "homepage": "https://github.com/wasmgroundup/emit#readme",
32
32
  "devDependencies": {
33
+ "@arethetypeswrong/cli": "^0.18.2",
33
34
  "@types/node": "^24.10.1",
34
35
  "prettier": "^3.6.2",
36
+ "publint": "^0.3.17",
35
37
  "typescript": "^5.9.3"
36
38
  },
37
39
  "scripts": {
38
40
  "build": "tsc",
39
41
  "format": "npx prettier '**/*.{ts,js,json}' --write",
42
+ "lint": "publint && attw --pack . --ignore-rules cjs-resolves-to-esm",
43
+ "pretest": "node scripts/extract-readme-example.js",
40
44
  "test": "node --test",
41
45
  "test:watch": "node --test --watch"
42
46
  }