A WASM based PHP Formatter
npm install @wasm-fmt/mago_fmt

``bash`
npm install @wasm-fmt/mago_fmt

`bash`
npx jsr add @fmt/mago-fmt
`javascript
import { format } from "@wasm-fmt/mago_fmt";
const input = function hello( \$name ) {
echo "Hello, " . \$name;
}
?>;
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 = function hello( \$name ) {
echo "Hello, " . \$name;
}
?>;
const formatted = format_with_version(input, "8.3", "main.php", {
"use-tabs": false,
"tab-width": 4,
"print-width": 120,
});
console.log(formatted);
`
For web environments, you need to initialize WASM module manually:
`javascript
import init, { format } from "@wasm-fmt/mago_fmt/web";
await init();
const input = function hello( \$name ) {
echo "Hello, " . \$name;
}
?>;
const formatted = format(input, "main.php", {
"use-tabs": false,
"tab-width": 4,
"print-width": 120,
});
console.log(formatted);
`
`JavaScript
import init, { format } from "@wasm-fmt/mago_fmt/vite";
await init();
// ...
`
- . - 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)
-
Thanks to:
- The Mago project created by Carthage Software