From 8b4a50647db02a5278de8ab7520ba1136f096be2 Mon Sep 17 00:00:00 2001 From: mProjectsCode Date: Tue, 31 May 2022 23:17:37 +0200 Subject: [PATCH] YAML converter indentation fix --- src/utils/YAMLConverter.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils/YAMLConverter.ts b/src/utils/YAMLConverter.ts index a59d411..7cec238 100644 --- a/src/utils/YAMLConverter.ts +++ b/src/utils/YAMLConverter.ts @@ -3,13 +3,13 @@ export class YAMLConverter { let output = ''; for (const [key, value] of Object.entries(obj)) { - output += `${key}: ${YAMLConverter.toYamlString(value)}\n`; + output += `${key}: ${YAMLConverter.toYamlString(value, 0)}\n`; } return output; } - private static toYamlString(value: any): string { + private static toYamlString(value: any, indentation: number): string { if (typeof value === 'boolean') { return value ? 'true' : 'false'; } else if (typeof value === 'number') { @@ -21,15 +21,19 @@ export class YAMLConverter { if (Array.isArray(value)) { for (const valueElement of value) { - output += `\n - ${YAMLConverter.toYamlString(valueElement)}`; + output += `\n${YAMLConverter.calculateSpacing(indentation)} - ${YAMLConverter.toYamlString(valueElement, indentation + 1)}`; } } else { for (const [objKey, objValue] of Object.entries(value)) { - output += `\n ${objKey}: ${YAMLConverter.toYamlString(objValue)}`; + output += `\n${YAMLConverter.calculateSpacing(indentation)} ${objKey}: ${YAMLConverter.toYamlString(objValue, indentation + 1)}`; } } return output; } } + + private static calculateSpacing(indentation: number): string { + return ' '.repeat(indentation * 4); + } }