msgpackr 1.9.3 → 1.9.5-debug.1
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/dist/index-no-eval.cjs +21 -6
- 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 -6
- 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 +31 -11
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +49 -11
- package/dist/test.js.map +1 -1
- package/index.d.cts +2 -1
- package/index.d.ts +2 -1
- package/pack.js +21 -6
- package/package.json +1 -1
- package/struct.js +10 -5
package/dist/index.js
CHANGED
|
@@ -1573,8 +1573,13 @@
|
|
|
1573
1573
|
if (Array.isArray(value)) {
|
|
1574
1574
|
packArray(value);
|
|
1575
1575
|
} else {
|
|
1576
|
-
|
|
1577
|
-
|
|
1576
|
+
// use this as an alternate mechanism for expressing how to serialize
|
|
1577
|
+
if (value.toJSON) {
|
|
1578
|
+
const json = value.toJSON();
|
|
1579
|
+
// if for some reason value.toJSON returns itself it'll loop forever
|
|
1580
|
+
if (json !== value)
|
|
1581
|
+
return pack(json)
|
|
1582
|
+
}
|
|
1578
1583
|
|
|
1579
1584
|
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1580
1585
|
if (type === 'function')
|
|
@@ -1619,7 +1624,7 @@
|
|
|
1619
1624
|
}
|
|
1620
1625
|
};
|
|
1621
1626
|
|
|
1622
|
-
const writePlainObject = this.variableMapSize ? (object) => {
|
|
1627
|
+
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
|
|
1623
1628
|
// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
1624
1629
|
let keys = Object.keys(object);
|
|
1625
1630
|
let length = keys.length;
|
|
@@ -1635,9 +1640,19 @@
|
|
|
1635
1640
|
position += 4;
|
|
1636
1641
|
}
|
|
1637
1642
|
let key;
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1643
|
+
if (this.coercibleKeyAsNumber) {
|
|
1644
|
+
for (let i = 0; i < length; i++) {
|
|
1645
|
+
key = keys[i];
|
|
1646
|
+
let num = Number(key);
|
|
1647
|
+
pack(isNaN(num) ? key : num);
|
|
1648
|
+
pack(object[key]);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
} else {
|
|
1652
|
+
for (let i = 0; i < length; i++) {
|
|
1653
|
+
pack(key = keys[i]);
|
|
1654
|
+
pack(object[key]);
|
|
1655
|
+
}
|
|
1641
1656
|
}
|
|
1642
1657
|
} :
|
|
1643
1658
|
(object, safePrototype) => {
|