https://github.com/wasm-fmt/mago_fmt
A WASM based PHP Formatter
https://github.com/wasm-fmt/mago_fmt
formatter formatting mago php wasm web webassembly
Last synced: 3 months ago
JSON representation
A WASM based PHP Formatter
- Host: GitHub
- URL: https://github.com/wasm-fmt/mago_fmt
- Owner: wasm-fmt
- License: mit
- Created: 2025-12-07T14:52:02.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-01-10T14:29:28.000Z (6 months ago)
- Last Synced: 2026-01-11T04:10:38.534Z (5 months ago)
- Topics: formatter, formatting, mago, php, wasm, web, webassembly
- Language: Rust
- Homepage:
- Size: 205 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/wasm-fmt/mago_fmt/actions/workflows/test.yml)
# Install
[](https://www.npmjs.com/package/@wasm-fmt/mago_fmt)
```bash
npm install @wasm-fmt/mago_fmt
```
[](https://jsr.io/@fmt/mago-fmt)
```bash
npx jsr add @fmt/mago-fmt
```
# Usage
## Node.js / Deno / Bun / Bundler
```javascript
import { format } from "@wasm-fmt/mago_fmt";
const input = ``;
const formatted = format(input, "main.php", {
"use-tabs": false,
"tab-width": 4,
"print-width": 120,
});
console.log(formatted);
```
With specific PHP version:
```javascript
import { format_with_version } from "@wasm-fmt/mago_fmt";
const input = ``;
const formatted = format_with_version(input, "8.3", "main.php", {
"use-tabs": false,
"tab-width": 4,
"print-width": 120,
});
console.log(formatted);
```
## Web
For web environments, you need to initialize WASM module manually:
```javascript
import init, { format } from "@wasm-fmt/mago_fmt/web";
await init();
const input = ``;
const formatted = format(input, "main.php", {
"use-tabs": false,
"tab-width": 4,
"print-width": 120,
});
console.log(formatted);
```
### Vite
```JavaScript
import init, { format } from "@wasm-fmt/mago_fmt/vite";
await init();
// ...
```
Or use the `./bundler` entry with [vite-plugin-wasm](https://www.npmjs.com/package/vite-plugin-wasm)
```javascript
import { format } from "@wasm-fmt/mago_fmt/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)
# Credits
Thanks to:
- The [Mago](https://github.com/carthage-software/mago) project created by [Carthage Software](https://github.com/carthage-software)