feat: preserve EOL in files (#16087)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Adib234 <30782825+Adib234@users.noreply.github.com>
Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
This commit is contained in:
Thomas Shephard
2026-01-30 00:57:06 +00:00
committed by GitHub
parent d43d772e65
commit 695785c69d
7 changed files with 353 additions and 18 deletions
+11
View File
@@ -54,6 +54,17 @@ export function isBinary(
return false;
}
/**
* Detects the line ending style of a string.
* @param content The string content to analyze.
* @returns '\r\n' for Windows-style, '\n' for Unix-style.
*/
export function detectLineEnding(content: string): '\r\n' | '\n' {
// If a Carriage Return is found, assume Windows-style endings.
// This is a simple but effective heuristic.
return content.includes('\r\n') ? '\r\n' : '\n';
}
/**
* Truncates a string to a maximum length, appending a suffix if truncated.
* @param str The string to truncate.