msgpackr 1.9.4 → 1.9.5
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 +7 -2
- 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 +7 -2
- 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 +7 -2
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +18 -2
- package/dist/test.js.map +1 -1
- package/pack.js +7 -2
- package/package.json +1 -1
package/dist/test.js
CHANGED
|
@@ -1635,8 +1635,13 @@
|
|
|
1635
1635
|
if (Array.isArray(value)) {
|
|
1636
1636
|
packArray(value);
|
|
1637
1637
|
} else {
|
|
1638
|
-
|
|
1639
|
-
|
|
1638
|
+
// use this as an alternate mechanism for expressing how to serialize
|
|
1639
|
+
if (value.toJSON) {
|
|
1640
|
+
const json = value.toJSON();
|
|
1641
|
+
// if for some reason value.toJSON returns itself it'll loop forever
|
|
1642
|
+
if (json !== value)
|
|
1643
|
+
return pack(json)
|
|
1644
|
+
}
|
|
1640
1645
|
|
|
1641
1646
|
// if there is a writeFunction, use it, otherwise just encode as undefined
|
|
1642
1647
|
if (type === 'function')
|
|
@@ -4098,6 +4103,17 @@
|
|
|
4098
4103
|
assert.deepEqual(values, [[1,0,1], [2,1,2], [3,2,3], [4,3,4]]);
|
|
4099
4104
|
});
|
|
4100
4105
|
|
|
4106
|
+
test('pack toJSON returning this', () => {
|
|
4107
|
+
class Serializable {
|
|
4108
|
+
someData = [1, 2, 3, 4]
|
|
4109
|
+
toJSON() {
|
|
4110
|
+
return this
|
|
4111
|
+
}
|
|
4112
|
+
}
|
|
4113
|
+
const serialized = pack(new Serializable);
|
|
4114
|
+
const deserialized = unpack(serialized);
|
|
4115
|
+
assert.deepStrictEqual(deserialized, { someData: [1, 2, 3, 4] });
|
|
4116
|
+
});
|
|
4101
4117
|
});
|
|
4102
4118
|
suite('msgpackr performance tests', function(){
|
|
4103
4119
|
test('performance JSON.parse', function() {
|