@@ -23,17 +23,20 @@ export class ParserService {
23
23
if ( typeof obj !== "object" || obj === null || obj === undefined ) {
24
24
const quotes = config . typeQuotes ( typeof obj ) ;
25
25
const color = config . typeColor ( typeof obj ) ;
26
- return `<tspan style="fill: ${ color } ;">${ quotes } ${ obj } ${ quotes } </tspan>` ;
26
+ const value = typeof obj !== 'function' ? obj : '<function>' ;
27
+ return `<tspan style="fill: ${ color } ;">${ quotes } ${ value } ${ quotes } </tspan>` ;
27
28
}
28
29
29
30
const entries = Object . entries ( obj )
30
31
. map ( ( [ key , value ] , index , array ) => {
31
32
const formattedValue = this . parse ( value , indent , depth + 1 ) ;
32
33
const comma = index < array . length - 1 ? ',' : '' ;
33
34
34
- return `<tspan x="${ nextIndent } " dy="19">` +
35
+ return (
36
+ `<tspan x="${ nextIndent } " dy="19">` +
35
37
`<tspan style="fill: ${ config . colors . keys } ;">"${ key } "</tspan>: ${ formattedValue } ${ comma } ` +
36
- `</tspan>` ;
38
+ `</tspan>`
39
+ ) ;
37
40
} )
38
41
. join ( `\n` ) ;
39
42
@@ -59,25 +62,21 @@ export class ParserService {
59
62
lineIndex : { current : number } = { current : 2 } ,
60
63
depth : number = 0
61
64
) : ObjectStructureInfo [ ] {
62
- if ( typeof obj !== 'object' || obj === null ) {
63
- return [ ] ;
64
- }
65
+ if ( typeof obj !== 'object' || obj === null ) return [ ] ;
65
66
66
67
const result : ObjectStructureInfo [ ] = [ ] ;
67
- const keys = Object . keys ( obj ) ;
68
-
69
- for ( const key of keys ) {
70
- const startLine = lineIndex . current ++ ;
71
68
72
- if ( typeof obj [ key ] === 'object' && obj [ key ] !== null ) {
73
- result . push ( { key, startLine, endLine : 0 , depth } ) ;
74
- const children = this . parseObjectStructure ( obj [ key ] , lineIndex , depth + 1 ) ;
75
- result . push ( ...children ) ;
76
- const endLine = lineIndex . current ++ ;
77
- result . find ( item => item . key === key && item . startLine === startLine ) ! . endLine = endLine ;
78
- }
79
- }
69
+ Object . entries ( obj )
70
+ . forEach ( ( [ key , value ] ) => {
71
+ const startLine = lineIndex . current ++ ;
80
72
73
+ if ( typeof value === 'object' && value !== null ) {
74
+ result . push ( { key, startLine, endLine : 0 , depth } ) ;
75
+ result . push ( ...this . parseObjectStructure ( value , lineIndex , depth + 1 ) ) ;
76
+ const endLinde = lineIndex . current ++ ;
77
+ result . find ( item => item . key === key && item . startLine === startLine ) ! . endLine = endLinde ;
78
+ }
79
+ } ) ;
81
80
return result ;
82
81
}
83
82
}
0 commit comments