cbor-x 1.5.2 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/decode.js +12 -1
- package/dist/decode-no-eval.cjs +12 -1
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +21 -3
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +20 -3
- package/dist/node.cjs.map +1 -1
- package/encode.js +9 -2
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/encode.js
CHANGED
|
@@ -4,7 +4,7 @@ try {
|
|
|
4
4
|
textEncoder = new TextEncoder()
|
|
5
5
|
} catch (error) {}
|
|
6
6
|
let extensions, extensionClasses
|
|
7
|
-
const Buffer = globalThis.Buffer
|
|
7
|
+
const Buffer = typeof globalThis === 'object' && globalThis.Buffer;
|
|
8
8
|
const hasNodeBuffer = typeof Buffer !== 'undefined'
|
|
9
9
|
const ByteArrayAllocate = hasNodeBuffer ? Buffer.allocUnsafeSlow : Uint8Array
|
|
10
10
|
const ByteArray = hasNodeBuffer ? Buffer : Uint8Array
|
|
@@ -557,6 +557,13 @@ export class Encoder extends Decoder {
|
|
|
557
557
|
error.iteratorNotHandled = true;
|
|
558
558
|
throw error;
|
|
559
559
|
}
|
|
560
|
+
if (this.useToJSON && value.toJSON) {
|
|
561
|
+
const json = value.toJSON()
|
|
562
|
+
// if for some reason value.toJSON returns itself it'll loop forever
|
|
563
|
+
if (json !== value)
|
|
564
|
+
return encode(json)
|
|
565
|
+
}
|
|
566
|
+
|
|
560
567
|
// no extension found, write as object
|
|
561
568
|
writeObject(value, !value.hasOwnProperty) // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
|
|
562
569
|
}
|
|
@@ -611,7 +618,7 @@ export class Encoder extends Decoder {
|
|
|
611
618
|
let key
|
|
612
619
|
if (encoder.keyMap) {
|
|
613
620
|
for (let i = 0; i < length; i++) {
|
|
614
|
-
encode(encodeKey(keys[i]))
|
|
621
|
+
encode(encoder.encodeKey(keys[i]))
|
|
615
622
|
encode(vals[i])
|
|
616
623
|
}
|
|
617
624
|
} else {
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cbor-x",
|
|
3
3
|
"author": "Kris Zyp",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.4",
|
|
5
5
|
"description": "Ultra-fast and conformant CBOR (RFC 8949) implementation with support for numerous tag extensions including records and structured cloning",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "./index.d.ts",
|