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