sandstone-mc/sandstone

Slightly unconventional `NBT.stringify` output

GrantGryczan opened this issue · 2 comments

Fixing #154 resulted in all NBT strings being delimited with apostrophes by default, not only the ones that needed it, despite that it is the most common convention to use quotation marks unless apostrophes are necessary to minimize usage of escapes.

image

Not that this is a big deal, but it should be very simple to fix by checking string.includes('"') before choosing the delimiter.

Actually, I'm not sure if this is a good idea to fix, since using quotation marks would technically result in non-minimal code with JSON.stringify(NBT.stringify('string')). Using apostrophes yields fewer escape characters in this case.

Reopening this because using apostrophes also yields more characters when the string contains apostrophes, so I think the decision here is more or less arbitrary, in which case the more conventional option (to only use apostrophes when the string contains quotation marks) might as well be picked.