Skip to content

wasm-fmt/gofmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

127 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test

Install

npm

npm install @wasm-fmt/gofmt

jsr.io

npx jsr add @fmt/gofmt

Usage

Node.js / Deno / Bun / Bundler

import { format } from "@wasm-fmt/gofmt";

const source = `
package main
import "fmt"
func main(){fmt.Println("Hello, 世界")
}
`;

const formatted = format(source);
console.log(formatted);

Web

For web environments, you need to initialize WASM module manually:

import init, { format } from "@wasm-fmt/gofmt/web";

await init();

const source = `
package main
import "fmt"
func main(){fmt.Println("Hello, 世界")
}
`;

const formatted = format(source);
console.log(formatted);

Vite

import init, { format } from "@wasm-fmt/gofmt/vite";

await init();
// ...

Or use the ./bundler entry with vite-plugin-wasm

import { format } from "@wasm-fmt/gofmt/bundler";

Entry Points

  • . - Auto-detects environment (Node.js uses node, Webpack uses bundler, default is ESM)
  • ./node - Node.js environment (no init required)
  • ./esm - ESM environments like Deno (no init required)
  • ./bundler - Bundlers like Webpack (no init required)
  • ./web - Web browsers (requires manual init)
  • ./vite - Vite bundler (requires manual init)

Build from source

# 1. install Go https://go.dev/doc/install

# 2. install TinyGo https://tinygo.org/getting-started/install/

# 3. clone this repo
git clone https://github.com/wasm-fmt/gofmt.git

# 4. build
npm run build

# 6. test
npm run test:node

Packages

 
 
 

Contributors

Languages