(text: string)
| 38 | } |
| 39 | |
| 40 | export function detectSourceEol(text: string): SourceFileEol { |
| 41 | const crlf = (text.match(/\r\n/g) ?? []).length; |
| 42 | const withoutCrlf = text.replace(/\r\n/g, ""); |
| 43 | const loneCr = (withoutCrlf.match(/\r/g) ?? []).length; |
| 44 | const loneLf = (withoutCrlf.match(/\n/g) ?? []).length; |
| 45 | const lf = loneLf + loneCr; |
| 46 | |
| 47 | if (crlf === 0 && lf === 0) return "none"; |
| 48 | if (crlf > 0 && lf === 0) return "crlf"; |
| 49 | if (crlf === 0 && lf > 0) return "lf"; |
| 50 | return "mixed"; |
| 51 | } |
| 52 | |
| 53 | export function applySourceEolPolicy(text: string, eol: SourceFileEol): string { |
| 54 | const normalized = text.replace(/\r\n?/g, "\n"); |
no test coverage detected