cbor-x 1.5.7 → 1.5.9
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 +22 -4
- package/dist/decode-no-eval.cjs +22 -4
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +35 -17
- 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 +35 -17
- 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 +35 -17
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +88 -28
- package/dist/test.js.map +1 -1
- package/encode.js +13 -13
- package/index.d.ts +6 -0
- package/package.json +9 -3
package/encode.js
CHANGED
|
@@ -469,7 +469,7 @@ export class Encoder extends Decoder {
|
|
|
469
469
|
}
|
|
470
470
|
let constructor = value.constructor
|
|
471
471
|
if (constructor === Object) {
|
|
472
|
-
writeObject(value
|
|
472
|
+
writeObject(value)
|
|
473
473
|
} else if (constructor === Array) {
|
|
474
474
|
length = value.length
|
|
475
475
|
if (length < 0x18) {
|
|
@@ -564,8 +564,8 @@ export class Encoder extends Decoder {
|
|
|
564
564
|
return encode(json)
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
-
// no extension found, write as object
|
|
568
|
-
writeObject(value
|
|
567
|
+
// no extension found, write as a plain object
|
|
568
|
+
writeObject(value)
|
|
569
569
|
}
|
|
570
570
|
}
|
|
571
571
|
} else if (type === 'boolean') {
|
|
@@ -628,19 +628,19 @@ export class Encoder extends Decoder {
|
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
} :
|
|
631
|
-
(object
|
|
631
|
+
(object) => {
|
|
632
632
|
target[position++] = 0xb9 // always use map 16, so we can preallocate and set the length afterwards
|
|
633
633
|
let objectOffset = position - start
|
|
634
634
|
position += 2
|
|
635
635
|
let size = 0
|
|
636
636
|
if (encoder.keyMap) {
|
|
637
|
-
for (let key in object) if (
|
|
637
|
+
for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
|
|
638
638
|
encode(encoder.encodeKey(key))
|
|
639
639
|
encode(object[key])
|
|
640
640
|
size++
|
|
641
641
|
}
|
|
642
642
|
} else {
|
|
643
|
-
for (let key in object) if (
|
|
643
|
+
for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
|
|
644
644
|
encode(key)
|
|
645
645
|
encode(object[key])
|
|
646
646
|
size++
|
|
@@ -649,7 +649,7 @@ export class Encoder extends Decoder {
|
|
|
649
649
|
target[objectOffset++ + start] = size >> 8
|
|
650
650
|
target[objectOffset + start] = size & 0xff
|
|
651
651
|
} :
|
|
652
|
-
(object,
|
|
652
|
+
(object, skipValues) => {
|
|
653
653
|
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
|
|
654
654
|
let newTransitions = 0
|
|
655
655
|
let length = 0
|
|
@@ -668,7 +668,7 @@ export class Encoder extends Decoder {
|
|
|
668
668
|
transition = nextTransition
|
|
669
669
|
}
|
|
670
670
|
} else {
|
|
671
|
-
for (let key in object) if (
|
|
671
|
+
for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
|
|
672
672
|
nextTransition = transition[key]
|
|
673
673
|
if (!nextTransition) {
|
|
674
674
|
if (transition[RECORD_SYMBOL] & 0x100000) {// this indicates it is a brancheable/extendable terminal node, so we will use this record id and extend it
|
|
@@ -728,9 +728,9 @@ export class Encoder extends Decoder {
|
|
|
728
728
|
writeArrayHeader(length + 2)
|
|
729
729
|
encode(0xe000 + recordId)
|
|
730
730
|
encode(keys)
|
|
731
|
-
if (
|
|
731
|
+
if (skipValues) return; // special exit for iterator
|
|
732
732
|
for (let key in object)
|
|
733
|
-
if (
|
|
733
|
+
if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
|
|
734
734
|
encode(object[key])
|
|
735
735
|
return
|
|
736
736
|
}
|
|
@@ -740,9 +740,9 @@ export class Encoder extends Decoder {
|
|
|
740
740
|
} else {
|
|
741
741
|
writeArrayHeader(length)
|
|
742
742
|
}
|
|
743
|
-
if (
|
|
743
|
+
if (skipValues) return; // special exit for iterator
|
|
744
744
|
for (let key in object)
|
|
745
|
-
if (
|
|
745
|
+
if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key))
|
|
746
746
|
encode(object[key])
|
|
747
747
|
}
|
|
748
748
|
const makeRoom = (end) => {
|
|
@@ -780,7 +780,7 @@ export class Encoder extends Decoder {
|
|
|
780
780
|
if (constructor === Object) {
|
|
781
781
|
let useRecords = encoder.useRecords !== false;
|
|
782
782
|
if (useRecords)
|
|
783
|
-
writeObject(object,
|
|
783
|
+
writeObject(object, true); // write the record identifier
|
|
784
784
|
else
|
|
785
785
|
writeEntityLength(Object.keys(object).length, 0xa0);
|
|
786
786
|
for (let key in object) {
|
package/index.d.ts
CHANGED
|
@@ -66,3 +66,9 @@ export class DecoderStream extends Transform {
|
|
|
66
66
|
export class EncoderStream extends Transform {
|
|
67
67
|
constructor(options?: Options | { highWaterMark: number, emitClose: boolean, allowHalfOpen: boolean })
|
|
68
68
|
}
|
|
69
|
+
|
|
70
|
+
export class Tag {
|
|
71
|
+
constructor(value: any, tagNumber: number)
|
|
72
|
+
value: any
|
|
73
|
+
tag: number
|
|
74
|
+
}
|
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.9",
|
|
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",
|
|
@@ -55,8 +55,14 @@
|
|
|
55
55
|
"import": "./decode.js"
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"./decode-no-eval":
|
|
59
|
-
|
|
58
|
+
"./decode-no-eval": {
|
|
59
|
+
"types": "./decode.d.ts",
|
|
60
|
+
"default": "./dist/decode-no-eval.cjs"
|
|
61
|
+
},
|
|
62
|
+
"./index-no-eval": {
|
|
63
|
+
"types": "./index.d.ts",
|
|
64
|
+
"default": "./dist/index-no-eval.cjs"
|
|
65
|
+
},
|
|
60
66
|
"./package.json": "./package.json"
|
|
61
67
|
},
|
|
62
68
|
"files": [
|