# tinygo-wasm-driver

> ## usage

Latest version **0.1.2** (published 2023-09-21) · 0 weekly downloads

## Install

```sh
npm install tinygo-wasm-driver
pnpm add tinygo-wasm-driver
yarn add tinygo-wasm-driver
bun add tinygo-wasm-driver
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; large bundle; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2023-09-21 |
| First published | 2023-09-21 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.9 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wanglei8381 |

## Links

- npm: https://www.npmjs.com/package/tinygo-wasm-driver
- npm.io page: https://npm.io/package/tinygo-wasm-driver

## Recent versions

- 0.1.2 (latest) — 2023-09-21
- 0.1.0 — 2023-09-21

## README

# tinygo-wasm-driver

## usage

go wasm

```go
func main() {
	wait := make(chan struct{}, 0)
  // 统一挂载在同一个全局变量
	js.Global().Get("__axe__").Set("stringMd5", js.FuncOf(StringMd5))
	js.Global().Get("__axe__").Set("uint8ArrayMd5", js.FuncOf(Uint8ArrayMd5))
	<-wait
}

func StringMd5(this js.Value, p []js.Value) interface{} {
	txt := p[0].String()
	sum := md5.Sum([]byte(txt))
	return hex.EncodeToString(sum[:])
}

func Uint8ArrayMd5(this js.Value, p []js.Value) interface{} {
	startTime := time.Now()
	buffer := make([]byte, p[0].Length())
	js.CopyBytesToGo(buffer, p[0])

	sum := md5.Sum(buffer)
	md5 := hex.EncodeToString(sum[:])

	endTime := time.Now()
	duration := endTime.Sub(startTime)
	fmt.Printf("时间差：%v\n", duration)
	return md5
}

```

js 调用

```ts
import { getAbility } from 'tinygo-wasm-driver';
// 将 go wasm 打包成图片
import wasm from './module.png';
import { useEffect } from 'react';

async function run() {
  const { stringMd5 } = await getAbility('__axe__', wasm);
  console.log(stringMd5('abc'));
}

```

## api

```ts
type getAbility = (globalName: string, wasmPath: string): Promise<any>

```
* globalName: go 中设置挂载的全局变量
* wasmPath: 打包的 wasm 文件，建议打包成 png 图片

---
_Source: https://npm.io/package/tinygo-wasm-driver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
