LongTengDao / j-toml

A Node.js implementation of TOML written by LongTengDao. Belong to "Plan J"./龙腾道为汤小明语写的 Node.js 实现。从属于“简计划”。
https://npmjs.com/package/@ltd/j-toml
GNU Lesser General Public License v3.0
55 stars 6 forks source link

Maintain "style" #26

Closed mustafa0x closed 1 year ago

mustafa0x commented 1 year ago

Hi, thanks for the wonderful library.

const doc = `title = "Development Page"
description = """
Multi
Line
Test
"""
`
const obj = toml.parse(doc, { joiner: "\n" });
obj.description = 'Multi\nLine\nTest\n1'
const out = toml.stringify(obj, { newline: "\n", T: " " });

Results in:

title = "Development Page"
description = "Multi\nLine\nTest\n1"

(description is no longer a multi-line string).

Similar applies to numbers (updating adds zeroes). Is there a way to maintain style even after editing? Even if it has to later be added in before converting back to toml.

Thanks!

LongTengDao commented 1 year ago

To specify exactly stringify style, please read https://github.com/LongTengDao/j-toml/tree/master/docs/English#tomlsection-tomlinline-tomlmultiline-tomlmultilinearray-tomlmultilinebasic-tomlbasic-tomlliteral-tomlcommentfor-tomlcommentforthis-tomlissection-tomlisinline (obj.description = toml.multiline.basic('Multi\nLine\nTest\n1')).

To preserve style from parse, please read https://github.com/LongTengDao/j-toml/blob/master/docs/English/xOptions.md#xoptionsliteral (read the notice before using xOptions).

It's hard to specify stringify style for most config file. All these features above in this library are mainly designed for "parse->modify->stringfy". If the parsed object also need to be used normally, copy it, or use it carefully.

mustafa0x commented 1 year ago

Thank you!