This repo is built on top of the toml-edit
crate. It brings toml-edit
to the JavaScript world through WebAssembly.
npm install @rainbowatcher/toml-edit-js
import init, {
edit, initSync, parse, stringify,
} from "@rainbowatcher/toml-edit-js"
const toml = `
[package]
rand = "1"
[profile.release]
strip = "symbols"
lto = true
codegen-units = 1
`
await init()
// or initSync()
const parsed = parse(toml)
/*
the parsed will be a js object as follow
{
"package": {
"rand": "1"
},
"profile": {
"release": {
"strip": "symbols",
"lto": true,
"codegen-units": 1
}
}
}
*/
const edited = edit(toml, "package.rand", { version: "1.0" })
/*
the edited will be a string as follow
[package]
rand = { version = "1.0" }
[profile.release]
strip = "symbols"
lto = true
codegen-units = 1
*/
const str = stringify(parsed)
/* same as const toml */
function parse(input: string): any
function stringify(input: any): string
function edit(input: string, path: string, value: any, option?: IEditOptions): string
edit method can receive a options
type IEditOptions = {
/**
* whether add the final newline
*/
finalNewline?: boolean
/**
* Write data in InlineTable format when the value to be written is a object type and inline is set to true
* @default true
*/
inline?: boolean
}
MIT.