Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write TOML files? #61

Open
bendavis78 opened this issue Jan 7, 2021 · 6 comments
Open

How to write TOML files? #61

bendavis78 opened this issue Jan 7, 2021 · 6 comments

Comments

@bendavis78
Copy link

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

@Orivoir
Copy link

Orivoir commented Nov 22, 2021

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

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

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

contributors = { name = "Baz Qux", email = "[email protected]", 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
Copy link

this lib doesn't support that

toml-node/index.js

Lines 4 to 9 in 4bad34e

module.exports = {
parse: function(input) {
var nodes = parser.parse(input.toString());
return compiler.compile(nodes);
}
};

@dzcpy
Copy link

dzcpy commented Feb 13, 2022

this lib doesn't support that

toml-node/index.js

Lines 4 to 9 in 4bad34e

module.exports = {
parse: function(input) {
var nodes = parser.parse(input.toString());
return compiler.compile(nodes);
}
};

Is there any lib that supports it?

@micalevisk
Copy link

@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
Copy link

dzcpy commented Feb 13, 2022

@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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants