cbor-redux
cbor-redux copied to clipboard
Add support for encoding numeric keys in maps
The library only accepts plain JS objects to represent CBOR maps, which prevents using numbers as keys. It would be good if JS Map
could be supported as that allows any type as key, in which case numbers could be used.
Assuming this would also encompass binary strings as map keys: I’d also find this useful for Perl-generated CBOR, in which case strings (including map keys) aren’t reliably text or binary.
Could this simply take the form of having CBOR maps become JS Map objects rather than plain-old objects?
This is a really good feedback. I haven't run into this usecase for my personal projects, but I've seen this in the wild and it's pretty darn common to need non-string keys.
I haven't had a lot of time to devote to CBOR in the last year but I'm hoping to push for some fixes for this as it relates to some server-side work in Deno this month.
I haven't lost sight and plan on getting this in soon.
Started work on this: https://github.com/aaronhuggins/cbor-redux/commit/5adf15e04d33f9eae480ce9d57d11751693ff87a
I'm also going to provide an options
API somehow, so that you can choose to use Map or Object as your dictionary for decode
; this would allow you to preserve non-string keys on parsing.