Skip to content

wasm-fmt/mago_fmt

Repository files navigation

Test

Install

npm

npm install @wasm-fmt/mago_fmt

jsr.io

npx jsr add @fmt/mago-fmt

Usage

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();
// ...

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

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:

Packages

 
 
 

Contributors

Languages