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/index-no-eval.cjs +14 -4
- 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 +14 -4
- 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 +14 -4
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +21 -4
- package/dist/test.js.map +1 -1
- package/index.d.cts +2 -1
- package/index.d.ts +2 -1
- package/pack.js +14 -4
- package/package.json +1 -1
package/dist/test.js
CHANGED
|
@@ -1681,7 +1681,7 @@
|
|
|
1681
1681
|
}
|
|
1682
1682
|
};
|
|
1683
1683
|
|
|
1684
|
-
const writePlainObject = this.variableMapSize ? (object) => {
|
|
1684
|
+
const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber) ? (object) => {
|
|
1685
1685
|
// this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
|
|
1686
1686
|
let keys = Object.keys(object);
|
|
1687
1687
|
let length = keys.length;
|
|
@@ -1697,9 +1697,19 @@
|
|
|
1697
1697
|
position += 4;
|
|
1698
1698
|
}
|
|
1699
1699
|
let key;
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1700
|
+
if (this.coercibleKeyAsNumber) {
|
|
1701
|
+
for (let i = 0; i < length; i++) {
|
|
1702
|
+
key = keys[i];
|
|
1703
|
+
let num = Number(key);
|
|
1704
|
+
pack(isNaN(num) ? key : num);
|
|
1705
|
+
pack(object[key]);
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
} else {
|
|
1709
|
+
for (let i = 0; i < length; i++) {
|
|
1710
|
+
pack(key = keys[i]);
|
|
1711
|
+
pack(object[key]);
|
|
1712
|
+
}
|
|
1703
1713
|
}
|
|
1704
1714
|
} :
|
|
1705
1715
|
(object, safePrototype) => {
|
|
@@ -3213,6 +3223,13 @@
|
|
|
3213
3223
|
assert.deepEqual(unpacked.map, {});
|
|
3214
3224
|
assert.deepEqual(unpacked.set, {});
|
|
3215
3225
|
});
|
|
3226
|
+
test('pack/unpack numeric coercible keys', function () {
|
|
3227
|
+
var data = { a: 1, 2: 'test', '-3.45': 'test2'};
|
|
3228
|
+
let packr = new Packr({variableMapSize: true, coercibleKeyAsNumber: true, useRecords: false});
|
|
3229
|
+
var serialized = packr.pack(data);
|
|
3230
|
+
var deserialized = packr.unpack(serialized);
|
|
3231
|
+
assert.deepEqual(deserialized, data);
|
|
3232
|
+
});
|
|
3216
3233
|
test('pack/unpack empty data with bundled strings', function () {
|
|
3217
3234
|
var data = {};
|
|
3218
3235
|
let packr = new Packr({bundleStrings: true});
|