-
-
Notifications
You must be signed in to change notification settings - Fork 136
feat: add deserializeComplexTypes option for Date round-tripping #208
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -304,6 +304,37 @@ export type Options<T extends Record<string, unknown>> = { | |||||||||||||||||||||||||
| @default 0o666 | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| readonly configFileMode?: number; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| Preserve non-JSON types like `Date` through serialization and deserialization. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| When enabled, `Date` objects are tagged during serialization so they can be restored as proper `Date` instances when read back. This allows round-tripping of `Date` values. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Uses a tagged wrapper format in the JSON: `{"$$type": "Date", "$$value": "2024-01-01T00:00:00.000Z"}`. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+309
to
+314
|
||||||||||||||||||||||||||
| Preserve non-JSON types like `Date` through serialization and deserialization. | |
| When enabled, `Date` objects are tagged during serialization so they can be restored as proper `Date` instances when read back. This allows round-tripping of `Date` values. | |
| Uses a tagged wrapper format in the JSON: `{"$$type": "Date", "$$value": "2024-01-01T00:00:00.000Z"}`. | |
| Preserve `Date` instances (and only `Date`) through serialization and deserialization. | |
| When enabled, `Date` objects are tagged during serialization so they can be restored as proper `Date` instances when read back. This allows round-tripping of `Date` values. | |
| Uses a tagged wrapper format in the JSON for `Date` values: `{"$$type": "Date", "$$value": "2024-01-01T00:00:00.000Z"}`. | |
| Other non-JSON types (such as `Map`, `Set`, or `BigInt`) are not currently preserved by this option and will not round-trip as their original types. |
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.
rawValue.toISOString()will throw aRangeErrorfor invalidDateinstances (e.g.new Date('not-a-date')), so enablingdeserializeComplexTypeswill currently make.set()fail for invalid dates. Handle invalid dates explicitly (for example, tag them with a sentinel and revive tonew Date(NaN), or store the original string and revive from that) so serialization doesn’t throw.