File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -3,13 +3,13 @@ export class YAMLConverter {
33 let output = '' ;
44
55 for ( const [ key , value ] of Object . entries ( obj ) ) {
6- output += `${ key } : ${ YAMLConverter . toYamlString ( value ) } \n` ;
6+ output += `${ key } : ${ YAMLConverter . toYamlString ( value , 0 ) } \n` ;
77 }
88
99 return output ;
1010 }
1111
12- private static toYamlString ( value : any ) : string {
12+ private static toYamlString ( value : any , indentation : number ) : string {
1313 if ( typeof value === 'boolean' ) {
1414 return value ? 'true' : 'false' ;
1515 } else if ( typeof value === 'number' ) {
@@ -21,15 +21,19 @@ export class YAMLConverter {
2121
2222 if ( Array . isArray ( value ) ) {
2323 for ( const valueElement of value ) {
24- output += `\n - ${ YAMLConverter . toYamlString ( valueElement ) } ` ;
24+ output += `\n${ YAMLConverter . calculateSpacing ( indentation ) } - ${ YAMLConverter . toYamlString ( valueElement , indentation + 1 ) } ` ;
2525 }
2626 } else {
2727 for ( const [ objKey , objValue ] of Object . entries ( value ) ) {
28- output += `\n ${ objKey } : ${ YAMLConverter . toYamlString ( objValue ) } ` ;
28+ output += `\n${ YAMLConverter . calculateSpacing ( indentation ) } ${ objKey } : ${ YAMLConverter . toYamlString ( objValue , indentation + 1 ) } ` ;
2929 }
3030 }
3131
3232 return output ;
3333 }
3434 }
35+
36+ private static calculateSpacing ( indentation : number ) : string {
37+ return ' ' . repeat ( indentation * 4 ) ;
38+ }
3539}
You can’t perform that action at this time.
0 commit comments