Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support Date object serialization, make json more consistent with JSON.stringify #58
feat: support Date object serialization, make json more consistent with JSON.stringify #58
Changes from 1 commit
924392d
d4ccf90
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on how we want to deal with #57, Is this what you'd expect when passing a Date/Map/Set while using
json: true
? Or would you want to throw an exception instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way this would need to be documented in the README under the
json
option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the behavior of
toJSON
. I'd like to add an additional flag in a subsequent PR (or, I suppose, in this PR) to let the user override that behavior independent of the JSON mode.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could include an
interpret
option that accepts values likeexpect-json
,coerce-json
, andjavascript
to switch between the options.expect-json
would throw on non-JSON-supported values;coerce-json
would invoketoJSON
and delegate toJSON.stringify
's behavior in other cases;javascript
would do its best to serialize all (non-circular) values for use in a js context.I don't need
expect-json
for my own work, butcoerce-json
would be extremely useful. I've also been wondering if we could introduce areplacer
-type option for both transforming and extending the supported values - e.g. we need strictcoerce-json
semantics, but also want to support theundefined
value. If you're amenable to that, I'll see what that would take.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way I've used
jsesc
is always very controlled, in that: if there's aDate
object, aMap
, aSet
, or aBigInt
somewhere in the input, and I am requesting JSON output viajson: true
, that's probably a mistake. I've only usedjsesc
in cases where I wantJSON.parse(output)
to produce an equivalent object again.So I defer to you on this. If you have a use case for it, that's great!