iarna / iarna-toml

Better TOML parsing and stringifying all in that familiar JSON interface.
ISC License
320 stars 43 forks source link

How can i stringify toml comment? #22

Open Gnosnay opened 5 years ago

Gnosnay commented 5 years ago

hey iarna~ this parser is so convenient to convert between toml and JSOject. but i have one question about that how can i insert the toml comment when i use TOML.stringify method to convert one js object to toml text?

i will appreciate it if u can give me some advice. thx a lot.

iarna commented 4 years ago

At this time, comments are not supported. The biggest limitation is just figuring out how this would be represented. It would be useful for someone interested to spend some time working up examples of how this might work... what the source object versus resulting TOML would look like, and vice-versa.

scriptcoded commented 4 years ago

@iarna What would the primary use case for comments in the output be? Just preserving them for doing machine edits of config files, or writing new comments?

iarna commented 4 years ago

@scriptcoded Probably both, certainly if it can do the first, then the second should be straightforward.

scriptcoded commented 4 years ago

@iarna Perhaps. In my head the hard thing with comments is that they don't have an unique identifier, which means that they can not be easily represented in a POJO. The first solution that came to me was to use random identifiers for comments. The issues with that are pretty obvious though, as there is a risk for collisions between comments and actual keys. Also, it's not a very friendly interface for developers.

Another idea might be to tie comment to properties, and return a separate object containing comments. For example:

# names contains a list of usernames and their IRL names.
# Multiline?
[names]
"foo" = "Mr. Foo"
# Nested comment?
"bar" = "The big Bar"
// Return value from `toml.parse`
{
  "data": { /* The normal output */ },
  "comments": {
    "names": "names contains a list of usernames and their IRL names.\\nMultiline?",
    "names.bar": "Nested comment?"
  }
}
jjeejj commented 3 years ago

comment is support now?