Skip to content

wasm-fmt/zig_fmt

Repository files navigation

Test npm

Install

npm install @wasm-fmt/zig_fmt

Usage

import init, { format } from "@wasm-fmt/zig_fmt";

await init();

const input = `
const std = @import("std");

pub fn main() !void 
{
  const stdout = std.io.getStdOut().writer();
  var i: usize = 1;
  while (i <= 16) : (i += 1) 
    {
        if (i % 15 == 0) 
      {
        try stdout.writeAll("ZiggZagg\\n");
      } else 
        if (i % 3 == 0) 
      {
        try stdout.writeAll("Zigg\\n");
      } else 
        if (i % 5 == 0) 
      {
        try stdout.writeAll("Zagg\\n");
      }
        else 
      {
        try stdout.print("{d}\\n", .{i});
      }
    }
}
`;

const formatted = format(input);
console.log(formatted);

For Vite users:

import init, { format } from "@wasm-fmt/zig_fmt/vite";

// ...