Skip to content

Commit 92c4648

Browse files
committed
fix(depth): fix depth for replace Big Ints
1 parent bfdbbea commit 92c4648

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/replaceBigInts.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
export default function replaceBigInts(obj: any): any {
2-
if (obj instanceof Array) {
3-
return obj.map(x => replaceBigInts(x));
4-
} else if (obj instanceof Object) {
2+
let depth = 100;
3+
if (obj instanceof Array) return obj.map((x, i) => (i < 100 ? replaceBigInts(x) : "Array too deep to display"));
4+
else if (obj instanceof Object) {
55
const newObj: any = {};
66
for (const key in obj) {
7-
newObj[key] = replaceBigInts(obj[key]!);
7+
depth++;
8+
if (depth < 100) newObj[key] = replaceBigInts(obj[key]!);
89
}
910
return newObj;
10-
} else if (typeof obj === "bigint") {
11-
return "bigint:" + obj.toString() + "";
12-
} else {
13-
return obj;
14-
}
11+
} else if (typeof obj === "bigint") return obj.toString() + "n";
12+
else return obj;
1513
}

0 commit comments

Comments
 (0)