npm install @wasm-fmt/taplo_fmtnpx jsr add @fmt/taplo-fmtimport init, { format } from "@wasm-fmt/taplo_fmt";
await init();
const input = `name = "example"
version = "0.1.0"
[dependencies]
serde = "1.0"`;
const formatted = format(input);
console.log(formatted);with custom options:
import init, { format } from "@wasm-fmt/taplo_fmt";
await init();
const input = `name = "example"
version = "0.1.0"
[dependencies]
serde = "1.0"`;
const formatted = format(input, {
column_width: 80,
indent_entries: true,
align_entries: true,
align_comments: true,
});
console.log(formatted);For Vite users:
Add "@wasm-fmt/taplo_fmt" to optimizeDeps.exclude in your vite config:
{
"optimizeDeps": {
"exclude": ["@wasm-fmt/taplo_fmt"]
}
}If you cannot change the vite config, you can use another import entry
import init, { format } from "@wasm-fmt/taplo_fmt/vite";
// ...Taplo is a TOML parser, analyzer, and formatter library, written in Rust.
This package is a WebAssembly build of the Taplo formatter, with a JavaScript wrapper.
Thanks to:
- The Taplo project created by Ferenc Tamás