msgpackr 1.11.6 → 1.11.7

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/pack.js CHANGED
@@ -123,10 +123,13 @@ export class Packr extends Unpackr {
123
123
  hasSharedUpdate = false
124
124
  let encodingError;
125
125
  try {
126
- if (packr.randomAccessStructure && value && value.constructor && (value.constructor === Object ||
127
- (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass))))
128
- writeStruct(value);
129
- else
126
+ if (packr.randomAccessStructure && value && value.constructor) {
127
+ if (value.constructor === Object) writeStruct(value); // simple object
128
+ else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
129
+ // allow user classes, if they don't need special handling (but do use toJSON if available)
130
+ writeStruct(value.toJSON ? value.toJSON() : value);
131
+ } else pack(value)
132
+ } else
130
133
  pack(value)
131
134
  let lastBundle = bundledStrings;
132
135
  if (bundledStrings)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.11.6",
4
+ "version": "1.11.7",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",