sandstone-mc / sandstone

Sandstone | Next Generation Framework for Minecraft
https://sandstone.dev/
MIT License
171 stars 15 forks source link

Slightly unconventional `NBT.stringify` output #157

Closed GrantGryczan closed 2 years ago

GrantGryczan commented 2 years ago

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.

GrantGryczan commented 2 years ago

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.

GrantGryczan commented 2 years ago

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.