Skip to content

wasm-fmt/taplo_fmt

Repository files navigation

Test

Install

npm

npm install @wasm-fmt/taplo_fmt

jsr.io

npx jsr add @fmt/taplo-fmt

Usage

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);
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";

// ...

How does it work?

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.

Credits

Thanks to:

About

A WASM based TOML Formatter

Topics

Resources

License

Stars

Watchers

Forks

Packages