@wasm-fmt/mago_fmt
v0.5.2
Published
A WASM based PHP Formatter
Readme
Install
npm install @wasm-fmt/mago_fmtnpx jsr add @fmt/mago-fmtUsage
Node.js / Deno / Bun / Bundler
import { format } from "@wasm-fmt/mago_fmt";
const input = `<?php
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:
import { format_with_version } from "@wasm-fmt/mago_fmt";
const input = `<?php
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);Web
For web environments, you need to initialize WASM module manually:
import init, { format } from "@wasm-fmt/mago_fmt/web";
await init();
const input = `<?php
function hello( \$name ) {
echo "Hello, " . \$name;
}
?>`;
const formatted = format(input, "main.php", {
"use-tabs": false,
"tab-width": 4,
"print-width": 120,
});
console.log(formatted);Vite
import init, { format } from "@wasm-fmt/mago_fmt/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)
Credits
Thanks to:
- The Mago project created by Carthage Software
