( aLinesDisplay: Array<string>, bLinesDisplay: Array<string>, aLinesCompare: Array<string>, bLinesCompare: Array<string>, options?: DiffOptions, )
| 120 | // Compare the pair of comparison arrays line-by-line. |
| 121 | // Format the corresponding lines in the pair of displayable arrays. |
| 122 | export function diffLinesUnified2( |
| 123 | aLinesDisplay: Array<string>, |
| 124 | bLinesDisplay: Array<string>, |
| 125 | aLinesCompare: Array<string>, |
| 126 | bLinesCompare: Array<string>, |
| 127 | options?: DiffOptions, |
| 128 | ): string { |
| 129 | if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) { |
| 130 | aLinesDisplay = [] |
| 131 | aLinesCompare = [] |
| 132 | } |
| 133 | if (isEmptyString(bLinesDisplay) && isEmptyString(bLinesCompare)) { |
| 134 | bLinesDisplay = [] |
| 135 | bLinesCompare = [] |
| 136 | } |
| 137 | |
| 138 | if ( |
| 139 | aLinesDisplay.length !== aLinesCompare.length |
| 140 | || bLinesDisplay.length !== bLinesCompare.length |
| 141 | ) { |
| 142 | // Fall back to diff of display lines. |
| 143 | return diffLinesUnified(aLinesDisplay, bLinesDisplay, options) |
| 144 | } |
| 145 | |
| 146 | const [diffs, truncated] = diffLinesRaw( |
| 147 | aLinesCompare, |
| 148 | bLinesCompare, |
| 149 | options, |
| 150 | ) |
| 151 | |
| 152 | // Replace comparison lines with displayable lines. |
| 153 | let aIndex = 0 |
| 154 | let bIndex = 0 |
| 155 | diffs.forEach((diff: Diff) => { |
| 156 | switch (diff[0]) { |
| 157 | case DIFF_DELETE: |
| 158 | diff[1] = aLinesDisplay[aIndex] |
| 159 | aIndex += 1 |
| 160 | break |
| 161 | |
| 162 | case DIFF_INSERT: |
| 163 | diff[1] = bLinesDisplay[bIndex] |
| 164 | bIndex += 1 |
| 165 | break |
| 166 | |
| 167 | default: |
| 168 | diff[1] = bLinesDisplay[bIndex] |
| 169 | aIndex += 1 |
| 170 | bIndex += 1 |
| 171 | } |
| 172 | }) |
| 173 | |
| 174 | return printDiffLines(diffs, truncated, normalizeDiffOptions(options)) |
| 175 | } |
| 176 | |
| 177 | // Compare two arrays of strings line-by-line. |
| 178 | export function diffLinesRaw( |
no test coverage detected