msgpackr 1.9.3 → 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/dist/node.cjs CHANGED
@@ -1686,7 +1686,7 @@ class Packr extends Unpackr {
1686
1686
  }
1687
1687
  };
1688
1688
 
1689
- const writePlainObject = this.variableMapSize ? (object) => {
1689
+ const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
1690
1690
  // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
1691
1691
  let keys = Object.keys(object);
1692
1692
  let length = keys.length;
@@ -1702,9 +1702,19 @@ class Packr extends Unpackr {
1702
1702
  position += 4;
1703
1703
  }
1704
1704
  let key;
1705
- for (let i = 0; i < length; i++) {
1706
- pack(key = keys[i]);
1707
- pack(object[key]);
1705
+ if (this.coercibleKeyAsNumber) {
1706
+ for (let i = 0; i < length; i++) {
1707
+ key = keys[i];
1708
+ let num = Number(key);
1709
+ pack(isNaN(num) ? key : num);
1710
+ pack(object[key]);
1711
+ }
1712
+
1713
+ } else {
1714
+ for (let i = 0; i < length; i++) {
1715
+ pack(key = keys[i]);
1716
+ pack(object[key]);
1717
+ }
1708
1718
  }
1709
1719
  } :
1710
1720
  (object, safePrototype) => {