msgpackr 1.9.2 → 1.9.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 +1 -1
- package/dist/index-no-eval.cjs +21 -7
- 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 +21 -7
- 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 +21 -7
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +96 -9
- 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 +3 -3
- package/index.d.ts +3 -3
- package/pack.js +18 -5
- package/package.json +1 -1
- package/unpack.js +3 -2
package/dist/node.cjs
CHANGED
|
@@ -988,10 +988,10 @@ const recordDefinition = (id, highByte) => {
|
|
|
988
988
|
currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
|
|
989
989
|
currentExtensions[0].noBuffer = true;
|
|
990
990
|
|
|
991
|
-
let
|
|
991
|
+
let errors = { Error, TypeError, ReferenceError };
|
|
992
992
|
currentExtensions[0x65] = () => {
|
|
993
993
|
let data = read();
|
|
994
|
-
return (
|
|
994
|
+
return (errors[data[0]] || Error)(data[1])
|
|
995
995
|
};
|
|
996
996
|
|
|
997
997
|
currentExtensions[0x69] = (data) => {
|
|
@@ -1029,6 +1029,7 @@ currentExtensions[0x73] = () => new Set(read());
|
|
|
1029
1029
|
|
|
1030
1030
|
const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
|
|
1031
1031
|
|
|
1032
|
+
let glbl = typeof globalThis === 'object' ? globalThis : window;
|
|
1032
1033
|
currentExtensions[0x74] = (data) => {
|
|
1033
1034
|
let typeCode = data[0];
|
|
1034
1035
|
let typedArrayName = typedArrays[typeCode];
|
|
@@ -1534,7 +1535,7 @@ class Packr extends Unpackr {
|
|
|
1534
1535
|
targetView.setFloat64(position, value);
|
|
1535
1536
|
position += 8;
|
|
1536
1537
|
}
|
|
1537
|
-
} else if (type === 'object') {
|
|
1538
|
+
} else if (type === 'object' || type === 'function') {
|
|
1538
1539
|
if (!value)
|
|
1539
1540
|
target[position++] = 0xc0;
|
|
1540
1541
|
else {
|
|
@@ -1641,6 +1642,11 @@ class Packr extends Unpackr {
|
|
|
1641
1642
|
} else {
|
|
1642
1643
|
if (value.toJSON) // use this as an alternate mechanism for expressing how to serialize
|
|
1643
1644
|
return pack(value.toJSON());
|
|
1645
|
+
|
|
1646
|
+
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1647
|
+
if (type === 'function')
|
|
1648
|
+
return pack(this.writeFunction && this.writeFunction(value));
|
|
1649
|
+
|
|
1644
1650
|
// no extension found, write as object
|
|
1645
1651
|
writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
|
|
1646
1652
|
}
|
|
@@ -1675,14 +1681,12 @@ class Packr extends Unpackr {
|
|
|
1675
1681
|
target[position++] = 0;
|
|
1676
1682
|
target[position++] = 0;
|
|
1677
1683
|
}
|
|
1678
|
-
} else if (type === 'function') {
|
|
1679
|
-
pack(this.writeFunction && this.writeFunction()); // if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1680
1684
|
} else {
|
|
1681
1685
|
throw new Error('Unknown type: ' + type)
|
|
1682
1686
|
}
|
|
1683
1687
|
};
|
|
1684
1688
|
|
|
1685
|
-
const
|
|
1689
|
+
const writePlainObject = this.variableMapSize ? (object) => {
|
|
1686
1690
|
// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
1687
1691
|
let keys = Object.keys(object);
|
|
1688
1692
|
let length = keys.length;
|
|
@@ -1717,7 +1721,9 @@ class Packr extends Unpackr {
|
|
|
1717
1721
|
}
|
|
1718
1722
|
target[objectOffset++ + start] = size >> 8;
|
|
1719
1723
|
target[objectOffset + start] = size & 0xff;
|
|
1720
|
-
}
|
|
1724
|
+
};
|
|
1725
|
+
|
|
1726
|
+
const writeRecord = this.useRecords === false ? writePlainObject :
|
|
1721
1727
|
(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)
|
|
1722
1728
|
(object, safePrototype) => {
|
|
1723
1729
|
let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
|
|
@@ -1789,6 +1795,14 @@ class Packr extends Unpackr {
|
|
|
1789
1795
|
if (safePrototype || object.hasOwnProperty(key))
|
|
1790
1796
|
pack(object[key]);
|
|
1791
1797
|
};
|
|
1798
|
+
|
|
1799
|
+
// craete reference to useRecords if useRecords is a function
|
|
1800
|
+
const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
|
|
1801
|
+
|
|
1802
|
+
const writeObject = checkUseRecords ? (object, safePrototype) => {
|
|
1803
|
+
checkUseRecords(object) ? writeRecord(object,safePrototype) : writePlainObject(object,safePrototype);
|
|
1804
|
+
} : writeRecord;
|
|
1805
|
+
|
|
1792
1806
|
const makeRoom = (end) => {
|
|
1793
1807
|
let newSize;
|
|
1794
1808
|
if (end > 0x1000000) {
|