cbor-x 1.6.0 → 1.6.3
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/README.md +8 -7
- package/decode.js +2 -2
- package/dist/decode-no-eval.cjs +2 -2
- package/dist/decode-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.cjs +13 -5
- 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 +13 -5
- 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 +13 -5
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +37 -6
- package/dist/test.js.map +1 -1
- package/encode.js +11 -3
- package/package.json +2 -2
package/dist/node.cjs
CHANGED
|
@@ -269,6 +269,7 @@ function read() {
|
|
|
269
269
|
}
|
|
270
270
|
token = dataView.getUint32(position$1);
|
|
271
271
|
position$1 += 4;
|
|
272
|
+
if (majorType === 1) return -1 - token; // can't safely use negation operator here
|
|
272
273
|
break
|
|
273
274
|
case 0x1b:
|
|
274
275
|
if (majorType == 7) {
|
|
@@ -283,8 +284,7 @@ function read() {
|
|
|
283
284
|
} else if (currentDecoder.int64AsNumber) {
|
|
284
285
|
token = dataView.getUint32(position$1) * 0x100000000;
|
|
285
286
|
token += dataView.getUint32(position$1 + 4);
|
|
286
|
-
} else
|
|
287
|
-
token = dataView.getBigUint64(position$1);
|
|
287
|
+
} else token = dataView.getBigUint64(position$1);
|
|
288
288
|
position$1 += 8;
|
|
289
289
|
break
|
|
290
290
|
case 0x1f:
|
|
@@ -1249,8 +1249,8 @@ class Encoder extends Decoder {
|
|
|
1249
1249
|
let structures;
|
|
1250
1250
|
let referenceMap;
|
|
1251
1251
|
options = options || {};
|
|
1252
|
-
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position
|
|
1253
|
-
return target.utf8Write(string, position,
|
|
1252
|
+
let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
|
|
1253
|
+
return target.utf8Write(string, position, target.byteLength - position)
|
|
1254
1254
|
} : (textEncoder && textEncoder.encodeInto) ?
|
|
1255
1255
|
function(string, position) {
|
|
1256
1256
|
return textEncoder.encodeInto(string, target.subarray(position)).written
|
|
@@ -1631,7 +1631,7 @@ class Encoder extends Decoder {
|
|
|
1631
1631
|
targetView.setUint32(position, value);
|
|
1632
1632
|
position += 4;
|
|
1633
1633
|
}
|
|
1634
|
-
} else if (!this.alwaysUseFloat && value >> 0 === value) { // negative integer
|
|
1634
|
+
} else if (!this.alwaysUseFloat && value >> 0 === value) { // negative integer, 31-bit or less
|
|
1635
1635
|
if (value >= -0x18) {
|
|
1636
1636
|
target[position++] = 0x1f - value;
|
|
1637
1637
|
} else if (value >= -0x100) {
|
|
@@ -1646,6 +1646,11 @@ class Encoder extends Decoder {
|
|
|
1646
1646
|
targetView.setUint32(position, ~value);
|
|
1647
1647
|
position += 4;
|
|
1648
1648
|
}
|
|
1649
|
+
} else if (!this.alwaysUseFloat && value < 0 && value >= -0x100000000 && Math.floor(value) === value) {
|
|
1650
|
+
// negative integer, 32-bit or less
|
|
1651
|
+
target[position++] = 0x3a;
|
|
1652
|
+
targetView.setUint32(position, -1 - value);
|
|
1653
|
+
position += 4;
|
|
1649
1654
|
} else {
|
|
1650
1655
|
let useFloat32;
|
|
1651
1656
|
if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
|
|
@@ -1687,6 +1692,9 @@ class Encoder extends Decoder {
|
|
|
1687
1692
|
}
|
|
1688
1693
|
let constructor = value.constructor;
|
|
1689
1694
|
if (constructor === Object) {
|
|
1695
|
+
if (this.skipFunction === true) {
|
|
1696
|
+
value = Object.fromEntries([...Object.keys(value).filter(x => typeof value[x] !== "function").map(x => [x, value[x]])]);
|
|
1697
|
+
}
|
|
1690
1698
|
writeObject(value);
|
|
1691
1699
|
} else if (constructor === Array) {
|
|
1692
1700
|
length = value.length;
|