@@ -40,19 +40,33 @@ export class ParserService {
4040 return `<tspan style="fill: ${ color } ;">${ quotes } ${ value } ${ quotes } </tspan>` ;
4141 }
4242
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 ) => {
4546 const formattedValue = this . parse ( value , indent , depth + 1 ) ;
46- const comma = index < array . length - 1 ? ',' : '' ;
47+ const comma = index < obj . length - 1 ? ',' : '' ;
4748
4849 return (
4950 `<tspan x="${ nextIndent } " dy="19">` +
50- `<tspan style="fill: ${ config . colors . keys } ;">" ${ key } "</tspan>: ${ formattedValue } ${ comma } ` +
51+ `${ formattedValue } ${ comma } ` +
5152 `</tspan>`
5253 ) ;
5354 } )
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 ? ',' : '' ;
5561
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+ }
5670 const bracket_color = config . bracketsColors ( depth ) ;
5771
5872 if ( currentIndent === 0 ) {
@@ -63,10 +77,11 @@ export class ParserService {
6377 ) ;
6478 }
6579
80+ const brackets = Array . isArray ( obj ) ? '[]' : '{}' ;
6681 return (
67- `<tspan style="fill: ${ bracket_color } ;">{ </tspan></tspan>\n` +
82+ `<tspan style="fill: ${ bracket_color } ;">${ brackets [ 0 ] } </tspan></tspan>\n` +
6883 `${ 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>`
7085 ) ;
7186 }
7287
0 commit comments