-
At the moment,
Thoughts on this? I think the following are the sane options that are available. If you prefer one over another, please react with the matching emoji and/or comment below.
|
Beta Was this translation helpful? Give feedback.
Replies: 13 comments
-
Matching JSON.stringify is a general choice. There is a slight difference between
Considering the compatibility, console.log(YAML.stringify([1,undefined, ,2]))
- 1
- null
- null
- 2 Returning 'null\n' is a better choice. |
Beta Was this translation helpful? Give feedback.
-
It may also be relevant to note that |
Beta Was this translation helpful? Give feedback.
-
Just came to this after being surprised that:
I would have expected "hello" to be absent, especially considering:
Regarding the conversation above, keep in mind that arrays in JS are different than Objects in terms of semantics. Non-serialized arrays can have "holes" and also want to preserve key index ordering, which is why
indexing While I'm not a YAML expert, I'd recommend hemming as close as possible to JSON and have two separate rules for objects vs arrays (lists)! |
Beta Was this translation helpful? Give feedback.
-
The behaviour of |
Beta Was this translation helpful? Give feedback.
-
I see. In view of this, matching JSON.stringify may be better. @eemeli Which one do you prefer?
|
Beta Was this translation helpful? Give feedback.
-
I asked the question because I'm not sure myself. :) Given the other JSON compatibility changes that are coming in #189, returning |
Beta Was this translation helpful? Give feedback.
-
Ah, my apologies! |
Beta Was this translation helpful? Give feedback.
-
Starting from the other side, Therefore, Note that If Since |
Beta Was this translation helpful? Give feedback.
-
Related issue in js-yaml: nodeca/js-yaml#565 |
Beta Was this translation helpful? Give feedback.
-
The way I see it, I'd be really rather leery of But of course JavaScript has more than one empty value, and that's where it all gets tricky. Not to mention that we could tell I'm currently finding myself arguing internally for pretty much all of the possibilities, one after the other. That of course would be a "fun" way of dealing with this (literally) undefined behaviour; select an option randomly each time. |
Beta Was this translation helpful? Give feedback.
-
If you want to start there, then I don't know of any other YAML implementation that returns their language's equivalent of
If you want to consider Hence, I think you can safely follow in JSON footsteps here... But I think |
Beta Was this translation helpful? Give feedback.
-
I decided to go with Thank you everyone for your feedback! |
Beta Was this translation helpful? Give feedback.
-
I wonder if
I'd prefer a cleaner |
Beta Was this translation helpful? Give feedback.
I decided to go with
undefined
. That matchesJSON.stringify()
, and it's at least not wrong. I also added a newkeepUndefined
option, which keepsundefined
values in mappings. That allows for local tags like!js/undefined
to be used, should that be desirable.Thank you everyone for your feedback!