@koordinates/xstate-tree 5.2.2 → 5.2.3
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/lib/utils.js +8 -1
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -161,9 +161,16 @@ function getCircularReplacer(stripKeys) {
|
|
|
161
161
|
return value;
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
+
function hasToJSON(value) {
|
|
165
|
+
return (typeof value === "object" &&
|
|
166
|
+
value !== null &&
|
|
167
|
+
typeof value.toJSON === "function");
|
|
168
|
+
}
|
|
164
169
|
function toJSON(value, stripKeys = []) {
|
|
165
170
|
const start = performance.now();
|
|
166
|
-
const result =
|
|
171
|
+
const result = hasToJSON(value)
|
|
172
|
+
? value.toJSON()
|
|
173
|
+
: JSON.parse(JSON.stringify(value, getCircularReplacer(stripKeys)));
|
|
167
174
|
const elapsed = performance.now() - start;
|
|
168
175
|
if (typeof result === "object" && result !== null) {
|
|
169
176
|
result.__toJSON_ms = Math.round(elapsed * 100) / 100;
|
package/package.json
CHANGED