https://github.com/wasm-fmt/gofmt
A WASM Based Golang Formatter
https://github.com/wasm-fmt/gofmt
formatter formatting go gofmt golang wasm webassembly
Last synced: 6 months ago
JSON representation
A WASM Based Golang Formatter
- Host: GitHub
- URL: https://github.com/wasm-fmt/gofmt
- Owner: wasm-fmt
- License: mit
- Created: 2023-08-04T02:35:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2026-01-11T05:28:35.000Z (6 months ago)
- Last Synced: 2026-01-11T12:42:42.719Z (6 months ago)
- Topics: formatter, formatting, go, gofmt, golang, wasm, webassembly
- Language: Go
- Homepage:
- Size: 443 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/wasm-fmt/gofmt/actions/workflows/test.yml)
# Install
[](https://www.npmjs.com/package/@wasm-fmt/gofmt)
```bash
npm install @wasm-fmt/gofmt
```
[](https://jsr.io/@fmt/gofmt)
```bash
npx jsr add @fmt/gofmt
```
# Usage
## Node.js / Deno / Bun / Bundler
```javascript
import { format } from "@wasm-fmt/gofmt";
const source = `
package main
import "fmt"
func main(){fmt.Println("Hello, 世界")
}
`;
const formatted = format(source);
console.log(formatted);
```
## Node.js < 22.19
```JavaScript
import { format } from "@wasm-fmt/gofmt/node";
```
## Web
For web environments, you need to initialize WASM module manually:
```javascript
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
```JavaScript
import init, { format } from "@wasm-fmt/gofmt/vite";
await init();
// ...
```
## 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
```bash
# 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
```