fix: initial (-) added to YAML output

This commit is contained in:
Chesterkxng
2025-04-06 01:47:10 +02:00
parent f6fd1d9a04
commit cdda783e47
2 changed files with 13 additions and 10 deletions

View File

@@ -19,18 +19,19 @@ function toYaml(
const lines = Object.entries(obj)
.map(([key, value]) => `${indent}${key}: ${value}`)
.join('\n');
return `${lines}`;
return `-\n${lines}`;
})
.join('\n-\n');
.join('\n');
}
// If input is string[][].
if (Array.isArray(input) && Array.isArray(input[0])) {
return (input as string[][])
.map((row) => {
return row.map((cell) => `${indent}- ${cell}`).join('\n');
const inner = row.map((cell) => `${indent}- ${cell}`).join('\n');
return `-\n${inner}`;
})
.join('\n-\n');
.join('\n');
}
return 'invalid input';