Skip to content

Commit

Permalink
Merge pull request #156 from vishnoianil/fix-newline
Browse files Browse the repository at this point in the history
Remove trailing new line from the downloaded yaml file
  • Loading branch information
nerdalert authored Sep 6, 2024
2 parents 1808a39 + 5a27c93 commit bd7b4b5
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/utils/yamlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,22 @@ function filterEmptyContext(data: unknown): unknown {
function trimTrailingSpaces(yamlString: string): string {
const hasTrailingNewline = yamlString.endsWith('\n');
const lines = yamlString.split('\n');
const trimmedLines = lines.map((line, index) => {
if (index === lines.length - 1 && line === '' && hasTrailingNewline) {
const trimmedLines = lines
.map((line, index) => {
if (index === lines.length - 1 && line === '' && hasTrailingNewline) {
return undefined;
}
// Preserve empty lines
if (line.trim() === '') return '';
// Trim trailing spaces, preserving indentation
const match = line.match(/^(\s*)(.*)$/);
if (match) {
const [, indent, content] = match;
return indent + content.trimEnd();
}
return line;
}
// Preserve empty lines
if (line.trim() === '') return '';
// Trim trailing spaces, preserving indentation
const match = line.match(/^(\s*)(.*)$/);
if (match) {
const [, indent, content] = match;
return indent + content.trimEnd();
}
return line;
});
})
.filter((line) => line !== undefined);

return trimmedLines.join('\n');
}
Expand Down

0 comments on commit bd7b4b5

Please sign in to comment.