(fileName: string, oldFileContent: string, newFileContent: string)
| 59 | * @see https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html |
| 60 | */ |
| 61 | export function diffFiles(fileName: string, oldFileContent: string, newFileContent: string) { |
| 62 | let unifiedDiff = createTwoFilesPatch(fileName, fileName, oldFileContent, newFileContent); |
| 63 | |
| 64 | const patchHeaderEnd = `--- ${fileName}\n+++ ${fileName}\n`; |
| 65 | const headerEndIndex = unifiedDiff.indexOf(patchHeaderEnd); |
| 66 | |
| 67 | if (headerEndIndex >= 0) { |
| 68 | unifiedDiff = unifiedDiff.slice(headerEndIndex + patchHeaderEnd.length); |
| 69 | } |
| 70 | |
| 71 | if (unifiedDiff === '') { |
| 72 | return undefined; |
| 73 | } |
| 74 | |
| 75 | return unifiedDiff; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Converts the unified diff to HTML. |
no outgoing calls
no test coverage detected