open-index/open-npm huggingface dataset:
npm package: @haribala/simple-physics
Description: Written in Rust and targetting WebAssembly, published as an NPM package. Meant for use in web apps for rendering physics simulations.
Latest version: 0.2.1

# Simply Physics Engine

Written in Rust and targetting WebAssembly, published as an NPM package.
Meant for use in web apps for rendering physics simulations.

## Steps to build and run sample app

### Prerequisites

- Rust and Cargo https://www.rust-lang.org/tools/install
- wasm-pack https://rustwasm.github.io/wasm-pack/installer/
- NodeJS (For runing sample app. Use NVM https://github.com/nvm-sh/nvm to install Node 16)

### Steps

1. Build the NPM package using `wasm-pack`
    ```
    $ make build
    ```
1. Run the sample web app that uses the NPM package
    ```
    $ make www-install-and-start
    ```
1. Go to http://localhost:8080/ in a browser

## References

- tutorials: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
npm package: @haribala/text-encoder-utf-8
Description: A simple text encoder/decoder for utf-8
Author: Harikrishnan Balagopal
Latest version: 1.1.1

# UTF-8 Text Encoder/Decoder

Encodes a string to UTF-8 encoded bytes. https://en.wikipedia.org/wiki/UTF-8
Decodes UTF-8 bytes to a string.

- No dependencies.
- Small code size and simple implementation that you can copy paste.

This can act as a polyfill for `TextEncoder` and `TextDecoder` if you only need UTF-8 encoding/decoding. Useful when `TextEncoder` and `TextDecoder` are undefined in places like the `AudioWorklet` API in browsers. See https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_AudioWorklet and https://github.com/rustwasm/wasm-bindgen/issues/2367 for more info.

## Usage

Install the package
https://www.npmjs.com/package/@haribala/text-encoder-utf-8
```
npm install @haribala/text-encoder-utf-8
```
or
```
pnpm add @haribala/text-encoder-utf-8
```

```js
import { encode, decode } from '@haribala/text-encoder-utf-8';

const a = 'hi there! 😃 🖐🏻';
const bytes = encode(a);
const b = decode(bytes);
console.log(a === b);
```
npm package: @haribala/wasm2js
Description: A compiler from WASM to JS written in Typescript.
Author: Harikrishnan Balagopal
Latest version: 1.1.1

# WASM to JS compiler

A compiler (decompiler?) from WebAssembly to Javascript written in Typescript.

https://www.npmjs.com/package/@haribala/wasm2js

Demos: https://haribala.dev/wasm2js

<img src="screenshots.png" alt="Screenshots of the demo apps" width="50%"/>

NOTE: This library is not the same as packages like
https://github.com/thlorenz/wasm2js , https://github.com/mafintosh/wat2js , etc.
which only embed the WASM binary in a Javascript module.
Unlike the above packages, this library parses the WASM binary
and compiles the abstract syntax tree to Javascript code instruction by instruction.
The result is similar to porting your WASM app to Javascript line by line.

Technically it might be called a decompiler since we are going from
a low-level assembly language (WASM) to a high-level language (Javascript).

## Usage

```js
import { compile, instantiate } from '@haribala/wasm2js';

const fetch_wasm_binary = async (url) => {
    const res = await fetch(url);
    if (!res.ok) throw new Error('failed to fetch the wasm binary');
    const wasmBytes = new Uint8Array(await res.arrayBuffer());
    return wasmBytes;
};

const compile_and_execute = async (wasmBytes) => {
    // Compile the wasm binary to javascript code.
    // The generated code is a string, so you can print it.
    const jsCode = compile(wasmBytes);
    console.log('javascript code:');
    console.log(jsCode);
    // Create an instance of the wasm module.
    // NOTE: 'instantiate' will also call the 'start' function if it exists.
    // https://webassembly.github.io/spec/core/text/modules.html#start-function
    const importObject = { /* imports required by the wasm module */ };
    const instance = instantiate(jsCode, importObject);
    console.log('instance:', instance);
    // Call an exported wasm function.
    const result = instance.exports.myfunc( /* arguments */ );
    return result;
};

fetch_wasm_binary('/url/to/myapp.wasm')
    .then(compile_and_execute)
    .then(console.log)
    .catch(console.error);
```

# API

```typescript
const compile: (
    wasmBytes: Uint8Array,
    debug_mode?: boolean = false,
    strict_maths?: boolean = true,
) => string;

const instantiate: (
    compiledJSCode: string,
    importObject: object,
) => MyWasmInstance;
```

The `debug_mode` optional parameter adds comments to the generated Javascript code so that it's easier to understand which WASM instructions got compiled to what JS. It also adds extra checks and `console.log` statements in the code to help detect bugs.

The `strict_maths` optional parameter is necessary for getting correct results from signed and unsigned math operations. However, it leads to a bigger code size and might slow down the execution.

## To do

- Add support for imported global variable immutability (const)
- Add support for vector/SIMD WASM instructions
- Add option to optimize the generated JS code. Example: `local.get 0, local.get 1, i32.add, local.set 0` -> `x = x + y`