CodeSampleX

샘플

superjson 2.2.6: See exactly what JSON.stringify destroys about a Date, Map, Set, BigInt, undefined, NaN, Infinity and RegExp, and which of them superjson puts back

검증된 샘플 — npm superjson 2.2.6: See exactly what JSON.stringify destroys about a Date, Map, Set, BigInt, undefined, NaN, Infinity and RegExp, and which of them…

sha256:97bbd6c4d7adf8fafd6021c2aa3a67ab2229cb30314cdd2e7106ba36b77a7316

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 node 22 linux x64 node 22 javascript npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-14
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-18

케이스

HOW
목표
See exactly what JSON.stringify destroys about a Date, Map, Set, BigInt, undefined, NaN, Infinity and RegExp, and which of them superjson puts back
패키지
심벌
  • superjson.stringify
  • superjson.parse
  • superjson.serialize
  • superjson.deserialize
  • superjson.registerClass
  • superjson.allowErrorProps
  • SuperJSONResult.meta
  • JSON.stringify
환경
node 22
생성일
2026-08-14T13:20:21Z

컨트랙트

  1. assert JSON.stringify throws a TypeError reading exactly "Do not know how to serialize a BigInt", naming no key, so one BigInt takes the whole document down
  2. assert every other loss is silent: JSON.stringify succeeds and turns the Date into a string that is no longer a Date
  3. assert Map, Set and RegExp all come back as {} from JSON.stringify, because their contents live in internal slots and only enumerable own properties are walked
  4. assert NaN and Infinity both become null, arriving indistinguishable from each other and from a real null
  5. assert the asymmetry: the same undefined is deleted from an object but coerced to null inside an array, so a record and a list do not survive the same round trip
  6. assert JSON.stringify(undefined) returns the value undefined rather than a string, so sending it directly sends invalid JSON
  7. assert superjson round-trips the whole fixture back to its own types: Date, Map, Set, bigint and RegExp, with NaN, Infinity and the exact 2^53+1 bigint value intact
  8. assert Number() on that bigint silently returns 2^53, which is why the throw exists and why the obvious workaround is wrong
  9. assert a Map keeps non-string keys, while the hand-rolled Object.fromEntries fix stringifies a number key and collapses an object key onto "[object Object]"
  10. assert both halves of the undefined asymmetry are repaired: the object key exists again and the array slot holds a real undefined rather than a hole
  11. assert restoration rebuilds rather than aliases, so the returned Date is a new object with the same instant
  12. assert nesting is not special-cased: a Date inside an array inside an object, and a Date held as a Map value, both come back
  13. assert negative zero survives superjson but not JSON.stringify, by the same route as NaN and Infinity: tagged "number" and carried as the string "-0"
  14. assert serialize returns exactly {json, meta}, with json being ordinary JSON that JSON.stringify accepts, and a rebuilt tree that does not alias the input
  15. assert meta.values is one dotted-path entry per rebuilt value with the tags Date, map, set, bigint, undefined, number and regexp, that the casing of a tag is not derivable, and that meta.v is 1
  16. assert URL is a second capitalised tag that superjson restores, and that plain JSON.stringify flattens a URL to its href because URL has a toJSON of its own, so toJSON is not Date-specific
  17. assert a path segment containing a dot is escaped in the meta key and that such a key round-trips intact
  18. assert meta is absent entirely rather than empty when nothing needed annotating, so reading result.meta.values on plain data throws
  19. assert reaching one object by two paths brings meta back on its own with referentialEqualities and no values, keyed by identity rather than by value, and that the annotation re-links the two copies so x === y survives the round trip
  20. assert deserialize takes the split back as an object, so the two pieces can travel separately
  21. assert stringify is exactly JSON.stringify of the split, and that a bare undefined becomes valid JSON here unlike JSON.stringify
  22. assert an unregistered class instance keeps its data, loses its prototype and methods, and is not annotated at all
  23. assert a function is left in json by serialize as a live reference and is only dropped by the JSON.stringify inside stringify, so json is typed JSONValue but is not always a JSON value
  24. assert an unregistered symbol value takes that same two-step path, and that plain JSON.stringify drops a symbol the same asymmetric way it drops undefined
  25. assert an Invalid Date is NOT restored: it is unannotated, passed through into json, then turned into null by Date.prototype.toJSON at the stringify step
  26. assert a TypeError comes back as a plain Error with the stack dropped, while JSON.stringify reports any Error as {} because message and stack are own but non-enumerable and name is not an own property
  27. assert the subclass survives only as data: the tag is the capitalised "Error" for every Error and the name string is reassigned onto a base Error, so err.name still reads TypeError while instanceof TypeError is false
  28. assert the dropped stack is opt-in rather than policy: allowErrorProps('stack') on a private instance carries it through stringify and parse, while the default instance measured above does not
  29. assert registerClass restores instanceof and methods and annotates the value as ["class", name]
  30. assert deserializing a class name this end never registered throws rather than degrading to a plain object
  31. assert registerClass mutates the singleton shared by every importer of the default export, while a private SuperJSON instance keeps its own registry

파일

  • csx.json
  • package-lock.json
  • package.json
  • src/roundtrip.mjs
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous