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/index.js CHANGED
@@ -1653,6 +1653,13 @@
1653
1653
  error.iteratorNotHandled = true;
1654
1654
  throw error;
1655
1655
  }
1656
+ if (this.useToJSON && value.toJSON) {
1657
+ const json = value.toJSON();
1658
+ // if for some reason value.toJSON returns itself it'll loop forever
1659
+ if (json !== value)
1660
+ return encode(json)
1661
+ }
1662
+
1656
1663
  // no extension found, write as object
1657
1664
  writeObject(value, !value.hasOwnProperty); // if it doesn't have hasOwnProperty, don't do hasOwnProperty checks
1658
1665
  }
@@ -1706,7 +1713,7 @@
1706
1713
  }
1707
1714
  if (encoder.keyMap) {
1708
1715
  for (let i = 0; i < length; i++) {
1709
- encode(encodeKey(keys[i]));
1716
+ encode(encoder.encodeKey(keys[i]));
1710
1717
  encode(vals[i]);
1711
1718
  }
1712
1719
  } else {