Commit 92c4648 1 parent bfdbbea commit 92c4648 Copy full SHA for 92c4648
File tree 1 file changed +7
-9
lines changed
1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change 1
1
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 ) {
5
5
const newObj : any = { } ;
6
6
for ( const key in obj ) {
7
- newObj [ key ] = replaceBigInts ( obj [ key ] ! ) ;
7
+ depth ++ ;
8
+ if ( depth < 100 ) newObj [ key ] = replaceBigInts ( obj [ key ] ! ) ;
8
9
}
9
10
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 ;
15
13
}
You can’t perform that action at this time.
0 commit comments