cbor-x 1.5.3 → 1.5.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
@@ -1696,6 +1696,13 @@ class Encoder extends Decoder {
1696
1696
  error.iteratorNotHandled = true;
1697
1697
  throw error;
1698
1698
  }
1699
+ if (this.useToJSON && value.toJSON) {
1700
+ const json = value.toJSON();
1701
+ // if for some reason value.toJSON returns itself it'll loop forever
1702
+ if (json !== value)
1703
+ return encode(json)
1704
+ }
1705
+
1699
1706
  // no extension found, write as object
1700
1707
  writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
1701
1708
  }
@@ -1749,7 +1756,7 @@ class Encoder extends Decoder {
1749
1756
  }
1750
1757
  if (encoder.keyMap) {
1751
1758
  for (let i = 0; i < length; i++) {
1752
- encode(encodeKey(keys[i]));
1759
+ encode(encoder.encodeKey(keys[i]));
1753
1760
  encode(vals[i]);
1754
1761
  }
1755
1762
  } else {