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/pack.js CHANGED
@@ -488,8 +488,13 @@ export class Packr extends Unpackr {
488
488
  if (Array.isArray(value)) {
489
489
  packArray(value)
490
490
  } else {
491
- if (value.toJSON) // use this as an alternate mechanism for expressing how to serialize
492
- return pack(value.toJSON());
491
+ // use this as an alternate mechanism for expressing how to serialize
492
+ if (value.toJSON) {
493
+ const json = value.toJSON()
494
+ // if for some reason value.toJSON returns itself it'll loop forever
495
+ if (json !== value)
496
+ return pack(json)
497
+ }
493
498
 
494
499
  // if there is a writeFunction, use it, otherwise just encode as undefined
495
500
  if (type === 'function')
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "msgpackr",
3
3
  "author": "Kris Zyp",
4
- "version": "1.9.4",
4
+ "version": "1.9.5",
5
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
6
  "license": "MIT",
7
7
  "types": "./index.d.ts",