msgpackr 1.9.2 → 1.9.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/README.md +1 -1
- package/dist/index-no-eval.cjs +34 -10
- 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 +34 -10
- 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 +34 -10
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +116 -12
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +3 -2
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/index.d.cts +4 -3
- package/index.d.ts +4 -3
- package/pack.js +31 -8
- package/package.json +1 -1
- package/unpack.js +3 -2
package/dist/index.js
CHANGED
|
@@ -932,10 +932,10 @@
|
|
|
932
932
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
933
933
|
currentExtensions[0].noBuffer = true;
|
|
934
934
|
|
|
935
|
-
let
|
|
935
|
+
let errors = { Error, TypeError, ReferenceError };
|
|
936
936
|
currentExtensions[0x65] = () => {
|
|
937
937
|
let data = read();
|
|
938
|
-
return (
|
|
938
|
+
return (errors[data[0]] || Error)(data[1])
|
|
939
939
|
};
|
|
940
940
|
|
|
941
941
|
currentExtensions[0x69] = (data) => {
|
|
@@ -973,6 +973,7 @@
|
|
|
973
973
|
|
|
974
974
|
const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
|
|
975
975
|
|
|
976
|
+
let glbl = typeof globalThis === 'object' ? globalThis : window;
|
|
976
977
|
currentExtensions[0x74] = (data) => {
|
|
977
978
|
let typeCode = data[0];
|
|
978
979
|
let typedArrayName = typedArrays[typeCode];
|
|
@@ -1467,7 +1468,7 @@
|
|
|
1467
1468
|
targetView.setFloat64(position, value);
|
|
1468
1469
|
position += 8;
|
|
1469
1470
|
}
|
|
1470
|
-
} else if (type === 'object') {
|
|
1471
|
+
} else if (type === 'object' || type === 'function') {
|
|
1471
1472
|
if (!value)
|
|
1472
1473
|
target[position++] = 0xc0;
|
|
1473
1474
|
else {
|
|
@@ -1574,6 +1575,11 @@
|
|
|
1574
1575
|
} else {
|
|
1575
1576
|
if (value.toJSON) // use this as an alternate mechanism for expressing how to serialize
|
|
1576
1577
|
return pack(value.toJSON());
|
|
1578
|
+
|
|
1579
|
+
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1580
|
+
if (type === 'function')
|
|
1581
|
+
return pack(this.writeFunction && this.writeFunction(value));
|
|
1582
|
+
|
|
1577
1583
|
// no extension found, write as object
|
|
1578
1584
|
writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
|
|
1579
1585
|
}
|
|
@@ -1608,14 +1614,12 @@
|
|
|
1608
1614
|
target[position++] = 0;
|
|
1609
1615
|
target[position++] = 0;
|
|
1610
1616
|
}
|
|
1611
|
-
} else if (type === 'function') {
|
|
1612
|
-
pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1613
1617
|
} else {
|
|
1614
1618
|
throw new Error('Unknown type: ' + type)
|
|
1615
1619
|
}
|
|
1616
1620
|
};
|
|
1617
1621
|
|
|
1618
|
-
const
|
|
1622
|
+
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
|
|
1619
1623
|
// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
1620
1624
|
let keys = Object.keys(object);
|
|
1621
1625
|
let length = keys.length;
|
|
@@ -1631,9 +1635,19 @@
|
|
|
1631
1635
|
position += 4;
|
|
1632
1636
|
}
|
|
1633
1637
|
let key;
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1638
|
+
if (this.coercibleKeyAsNumber) {
|
|
1639
|
+
for (let i = 0; i < length; i++) {
|
|
1640
|
+
key = keys[i];
|
|
1641
|
+
let num = Number(key);
|
|
1642
|
+
pack(isNaN(num) ? key : num);
|
|
1643
|
+
pack(object[key]);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
} else {
|
|
1647
|
+
for (let i = 0; i < length; i++) {
|
|
1648
|
+
pack(key = keys[i]);
|
|
1649
|
+
pack(object[key]);
|
|
1650
|
+
}
|
|
1637
1651
|
}
|
|
1638
1652
|
} :
|
|
1639
1653
|
(object, safePrototype) => {
|
|
@@ -1650,7 +1664,9 @@
|
|
|
1650
1664
|
}
|
|
1651
1665
|
target[objectOffset++ + start] = size >> 8;
|
|
1652
1666
|
target[objectOffset + start] = size & 0xff;
|
|
1653
|
-
}
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
const writeRecord = this.useRecords === false ? writePlainObject :
|
|
1654
1670
|
(options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
|
|
1655
1671
|
(object, safePrototype) => {
|
|
1656
1672
|
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
|
|
@@ -1722,6 +1738,14 @@
|
|
|
1722
1738
|
if (safePrototype || object.hasOwnProperty(key))
|
|
1723
1739
|
pack(object[key]);
|
|
1724
1740
|
};
|
|
1741
|
+
|
|
1742
|
+
// craete reference to useRecords if useRecords is a function
|
|
1743
|
+
const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
|
|
1744
|
+
|
|
1745
|
+
const writeObject = checkUseRecords ? (object, safePrototype) => {
|
|
1746
|
+
checkUseRecords(object) ? writeRecord(object,safePrototype) : writePlainObject(object,safePrototype);
|
|
1747
|
+
} : writeRecord;
|
|
1748
|
+
|
|
1725
1749
|
const makeRoom = (end) => {
|
|
1726
1750
|
let newSize;
|
|
1727
1751
|
if (end > 0x1000000) {
|