feat(extended)!: add cborg/extended module with full JavaScript type fidelity #168
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.
BREAKING CHANGE: Tag decoder signature changed from receiving the decoded
value to receiving a decode control object. See migration guide below.
Add new
cborg/extendedentry point providing encode/decode with built-insupport for Date, RegExp, Set, Map, BigInt, Error, and all TypedArrays using
standard CBOR tags. Type support is similar to the browser's structured
clone algorithm.
Key features:
The Map/object fidelity is achieved through a new tag decoder API that
gives decoders control over how their content is decoded. Tag 259 (Map)
uses
decode.entries()to preserve key types regardless of theuseMapssetting, while plain CBOR maps decode as objects.
Extends
cborg/taglibwith encoders and decoders for all supported types(previously only BigInt). Moves taglib.js to lib/taglib.js for consistency
(external API unchanged via package.json exports).
Also fixes a bug in lib/7float.js where -0 lost its sign bit during
half-precision float encoding (bitwise ops on floats convert to int32).
Migration for custom tag decoders:
Before:
After:
For tags wrapping CBOR maps that need non-string key preservation:
TypeScript users will see compile errors guiding the fix. JavaScript
users will see runtime errors if not updated (calling methods on a function).