@@ -40,19 +40,33 @@ export class ParserService {
40
40
return `<tspan style="fill: ${ color } ;">${ quotes } ${ value } ${ quotes } </tspan>` ;
41
41
}
42
42
43
- const entries = Object . entries ( obj )
44
- . map ( ( [ key , value ] , index , array ) => {
43
+ let entries = '' ;
44
+ if ( Array . isArray ( obj ) ) {
45
+ entries = obj . map ( ( value , index ) => {
45
46
const formattedValue = this . parse ( value , indent , depth + 1 ) ;
46
- const comma = index < array . length - 1 ? ',' : '' ;
47
+ const comma = index < obj . length - 1 ? ',' : '' ;
47
48
48
49
return (
49
50
`<tspan x="${ nextIndent } " dy="19">` +
50
- `<tspan style="fill: ${ config . colors . keys } ;">" ${ key } "</tspan>: ${ formattedValue } ${ comma } ` +
51
+ `${ formattedValue } ${ comma } ` +
51
52
`</tspan>`
52
53
) ;
53
54
} )
54
- . join ( `\n` ) ;
55
+ . join ( `\n` ) ;
56
+ } else {
57
+ entries = Object . entries ( obj )
58
+ . map ( ( [ key , value ] , index , array ) => {
59
+ const formattedValue = this . parse ( value , indent , depth + 1 ) ;
60
+ const comma = index < array . length - 1 ? ',' : '' ;
55
61
62
+ return (
63
+ `<tspan x="${ nextIndent } " dy="19">` +
64
+ `<tspan style="fill: ${ config . colors . keys } ;">"${ key } "</tspan>: ${ formattedValue } ${ comma } ` +
65
+ `</tspan>`
66
+ ) ;
67
+ } )
68
+ . join ( `\n` ) ;
69
+ }
56
70
const bracket_color = config . bracketsColors ( depth ) ;
57
71
58
72
if ( currentIndent === 0 ) {
@@ -63,10 +77,11 @@ export class ParserService {
63
77
) ;
64
78
}
65
79
80
+ const brackets = Array . isArray ( obj ) ? '[]' : '{}' ;
66
81
return (
67
- `<tspan style="fill: ${ bracket_color } ;">{ </tspan></tspan>\n` +
82
+ `<tspan style="fill: ${ bracket_color } ;">${ brackets [ 0 ] } </tspan></tspan>\n` +
68
83
`${ entries } \n` +
69
- `<tspan x="${ currentIndent } " dy="19"><tspan style="fill: ${ bracket_color } ;">}</tspan>`
84
+ `<tspan x="${ currentIndent } " dy="19"><tspan style="fill: ${ bracket_color } ;">${ brackets [ 1 ] } </tspan>`
70
85
) ;
71
86
}
72
87
0 commit comments