Skip to content

Commit c1a6e08

Browse files
authored
Merge pull request #16 from LovesWorking/display-value-fix
Display value fix
2 parents cf33e6c + 685e136 commit c1a6e08

File tree

3 files changed

+15
-44
lines changed

3 files changed

+15
-44
lines changed

package-lock.json

+1-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
},
4444
"dependencies": {
4545
"expo-clipboard": "~6.0.3",
46-
"fast-deep-equal": "^3.1.3",
47-
"superjson": "^2.2.1"
46+
"fast-deep-equal": "^3.1.3"
4847
}
4948
}
+13-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import { serialize } from "superjson";
2-
31
/**
42
* Displays a string regardless the type of the data
53
* @param {unknown} value Value to be stringified
64
* @param {boolean} beautify Formats json to multiline
75
*/
86
export const displayValue = (value: unknown, beautify: boolean = false) => {
9-
const { json } = serialize(value);
7+
const getCircularReplacer = () => {
8+
const seen = new WeakSet();
9+
return (key: string, value: any) => {
10+
if (typeof value === "object" && value !== null) {
11+
if (seen.has(value)) {
12+
return "[Circular]";
13+
}
14+
seen.add(value);
15+
}
16+
return value;
17+
};
18+
};
1019

11-
return JSON.stringify(json, null, beautify ? 2 : undefined);
20+
return JSON.stringify(value, getCircularReplacer(), beautify ? 2 : undefined);
1221
};

0 commit comments

Comments
 (0)