BinaryMuse / toml-node

TOML parser for Node.js and the Browser. Parses TOML v0.4.0
http://binarymuse.github.io/toml-node/
MIT License
306 stars 25 forks source link

How to write TOML files? #61

Open bendavis78 opened 3 years ago

bendavis78 commented 3 years ago

How do you write a js object to a TOML file?

Orivoir commented 2 years ago

The TOML spec Array provide a sample write with a pseudo JSON object as element.

contributors = [
  "Foo Bar <foo@example.com>",
  { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }
]

I think you can just use this object as key/value

contributors = { name = "Baz Qux", email = "bazqux@example.com", url = "https://example.com/bazqux" }

Other solution can be usage of TOML Table

[dog."tater.man"]
type.name = "pug"

The above table should be generate the below JSON

{ "dog": { "tater.man": { "type": { "name": "pug" } } } }
micalevisk commented 2 years ago

this lib doesn't support that

https://github.com/BinaryMuse/toml-node/blob/4bad34e1dc81586e799e269e5d2c78662b6657b2/index.js#L4-L9

dzcpy commented 2 years ago

this lib doesn't support that

https://github.com/BinaryMuse/toml-node/blob/4bad34e1dc81586e799e269e5d2c78662b6657b2/index.js#L4-L9

Is there any lib that supports it?

micalevisk commented 2 years ago

@dzcpy looks like this one does: https://github.com/tauri-apps/tauri-toml but the last commit was in 2019 :/

You can search for other here: https://npms.io/search?q=toml

dzcpy commented 2 years ago

@dzcpy looks like this one does: https://github.com/tauri-apps/tauri-toml but the last commit was in 2019 :/

You can search for other here: https://npms.io/search?q=toml

Thanks for your reply. I found this one might be a better alternative. It supports TOML 0.5 https://npmjs.com/package/@iarna/toml

1216892614 commented 1 year ago

Serializing toml is a strange requirement in my opinion, after all, Object2toml can have many different results. Maybe template strings are better suited for this?