Skip to main content
Home
This release is 3 versions behind 0.5.0 — the latest version of @fmt/mago-fmt. Jump to latest

Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, Bun, BrowsersIt is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Downloads3/wk
Published4 days ago (0.4.0)

A WASM based PHP Formatter

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

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:

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@fmt/mago-fmt

Import symbol

import * as mago_fmt from "@fmt/mago-fmt";
or

Import directly with a jsr specifier

import * as mago_fmt from "jsr:@fmt/mago-fmt";

Add Package

pnpm i jsr:@fmt/mago-fmt
or (using pnpm 10.8 or older)
pnpm dlx jsr add @fmt/mago-fmt

Import symbol

import * as mago_fmt from "@fmt/mago-fmt";

Add Package

yarn add jsr:@fmt/mago-fmt
or (using Yarn 4.8 or older)
yarn dlx jsr add @fmt/mago-fmt

Import symbol

import * as mago_fmt from "@fmt/mago-fmt";

Add Package

vlt install jsr:@fmt/mago-fmt

Import symbol

import * as mago_fmt from "@fmt/mago-fmt";

Add Package

npx jsr add @fmt/mago-fmt

Import symbol

import * as mago_fmt from "@fmt/mago-fmt";

Add Package

bunx jsr add @fmt/mago-fmt

Import symbol

import * as mago_fmt from "@fmt/mago-fmt";