wasm-modules-repository

repo
Created Jun 2025
Original
Go
Stars
0
Forks
0
Size
159.6 MB
Last Update
28 days ago

High-performance WebAssembly modules collection written in Go.

README.md

WASM Modules Repository 🚀

High-performance WebAssembly modules collection written in Go, designed for use with GoWM (Go Wasm Manager).

Built with a Go-based build system featuring parallel processing, advanced optimizations, and integrated toolchain management.

Available Modules

ModuleDescriptionFunctionsSize (wasm → gzip)
math-wasmMathematical calculationsadd, subtract, multiply, divide, power, factorial, sqrt, gcd, fibonacci, mean, median... (25)2.5M → 720K
crypto-wasmCryptographic operationshashSHA256, encryptAES, generateRSAKeyPair, generateJWT, bcryptHash, generateUUID... (19)6.1M → 1.7M
text-wasmAdvanced text processingtextSimilarity, levenshtein, slugify, camelCase, extractEmails, wordCount, readingTime... (17)3.8M → 1.1M
image-wasmImage processingcompressJPEG, compressPNG, convertToWebP, resizeImage, getImageInfo (5)3.0M → 864K
qr-wasmQR Codes & BarcodesgenerateQRCode, decodeQRCode, generateBarcode, decodeBarcode, generateVCard, generateWiFiQR (6)3.3M → 920K
pdf-wasmPDF generation & manipulationcreatePDF, mergePDFs, splitPDF, generateInvoice, generateReport, htmlToPDF, analyzePDF... (18)5.4M → 1.5M
jsonxml-wasmJSON/XML/CSV/YAML conversionparseJSON, validateJSON, parseXML, xmlToJSON, csvToJSON, yamlToJSON, jsonToYAML... (14)7.5M → 2.3M
goxios-wasmHTTP client (axios-like)get, post, put, delete, patch, request, create, setDefaults (8)11M → 2.7M
compress-wasmCompression & archivinggzipCompress, deflateCompress, lz4Compress, snappyCompress, zipCreate, tarCreate, analyzeCompression... (19)TBD
validation-wasmData validationvalidateEmail, validateURL, validatePhoneNumber, validateIBAN, validateCreditCard, validatePostalCode, validateJSONSchema, validateRegex... (16)TBD

Each module also exposes the utility functions setSilentMode, getAvailableFunctions, and getModuleInfo.

Quick Start

Prerequisites

  • Go 1.21+
  • (Optional) Binaryen for wasm-opt optimization

Setup

# Install dependencies and build the manager make setup # Or manually: go mod tidy go build -o wasm-manager .

Building Modules

# Build all modules (parallel) ./wasm-manager build # Build a specific module ./wasm-manager build math-wasm # Build multiple modules ./wasm-manager build math-wasm crypto-wasm qr-wasm # Build without optimization (faster for development) ./wasm-manager build --optimize=false # Clean build ./wasm-manager build --clean # Custom worker count ./wasm-manager build --workers 8

Available Commands

CommandDescriptionKey Options
buildBuild WASM modules--workers, --optimize, --clean, --compress, --integrity
validateValidate module structure--strict, --fix
testTest implementations--integration, --coverage
cleanRemove build artifacts--all, --cache
install-toolsInstall optimization tools--check, --force, --binaryen
./wasm-manager --help # Full help

Build System

Parallel Processing

  • Configurable worker pools (defaults to CPU core count)
  • Simultaneous multi-module builds
  • Error isolation: a failed build doesn't stop others

Optimization Pipeline

  • WASM optimization via wasm-opt (Binaryen)
  • Gzip and brotli compression
  • SHA256 hash generation (.wasm.integrity files)
  • Size reporting and compression ratios

Example Output

🚀 Building 8 modules with 8 workers

✅ math-wasm        2.5M → 720K (30s)
✅ crypto-wasm      6.1M → 1.7M (40s)
✅ image-wasm       3.0M → 864K (35s)
✅ qr-wasm          3.3M → 920K (36s)
✅ text-wasm        3.8M → 1.1M (38s)
✅ pdf-wasm         5.4M → 1.5M (40s)
✅ jsonxml-wasm     7.5M → 2.3M (44s)
✅ goxios-wasm       11M → 2.7M (45s)

📊 Statistics:
   Successful: 8
   Failed: 0
   Compression ratio: 27%

Module Structure

Each WASM module follows the same structure:

module-wasm/
├── main.go              # Go source code
├── go.mod               # Go dependencies
├── module.json          # Metadata (functions, examples, config)
├── main.wasm            # Compiled binary
├── main.wasm.gz         # Gzip compressed version
└── main.wasm.integrity  # SHA256 hash (SRI)

module.json

The module.json file describes the module for GoWM integration:

  • Metadata: name, version, description, author, license
  • Functions: list with parameters, return types, descriptions
  • Examples: ready-to-use code snippets
  • GoWM config: readySignal, standard functions, auto-detection
  • Build info: language, build command, target

Development Workflow

# 1. Edit the Go source code of a module # 2. Build and test ./wasm-manager build math-wasm --verbose ./wasm-manager test math-wasm # 3. Validate compliance ./wasm-manager validate math-wasm --strict # 4. Full production build ./wasm-manager clean --all ./wasm-manager install-tools --check ./wasm-manager build --workers 8 ./wasm-manager validate --strict

Creating a New Module

  1. Create a my-module-wasm/ directory
  2. Add main.go with functions exported via js.Global().Set()
  3. Add go.mod with the Go module
  4. Add module.json with metadata
  5. End main() with js.Global().Set("__gowm_ready", js.ValueOf(true)) and a blocking channel
  6. Build with ./wasm-manager build my-module-wasm

Minimal Template

//go:build js && wasm package main import ( "fmt" "syscall/js" ) func myFunction(this js.Value, args []js.Value) interface{} { // Implementation return js.ValueOf("result") } func main() { c := make(chan struct{}) js.Global().Set("myFunction", js.FuncOf(myFunction)) js.Global().Set("__gowm_ready", js.ValueOf(true)) fmt.Println("Module loaded") <-c }

Project Structure

wasm-modules-repository/
├── main.go              # Build manager entry point
├── go.mod               # Dependencies
├── Makefile             # Build automation
├── wasm-manager         # Compiled manager binary
├── cmd/                 # CLI commands (build, clean, test, validate, install)
├── internal/            # Internal logic (builder, cleaner, tester, validator)
├── shared/              # Shared resources (wasm_exec.js)
└── *-wasm/              # Individual WASM modules

License

MIT

Repository Topics
#gowm#wasm#webassembly