Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
reverse.js24 linesDownload Raw Back to patch
1export function reversePatch(structuredPatch) {
2    if (Array.isArray(structuredPatch)) {
3        // (See comment in unixToWin for why we need the pointless-looking anonymous function here)
4        return structuredPatch.map(patch => reversePatch(patch)).reverse();
5    }
6    return Object.assign(Object.assign({}, structuredPatch), { oldFileName: structuredPatch.newFileName, oldHeader: structuredPatch.newHeader, newFileName: structuredPatch.oldFileName, newHeader: structuredPatch.oldHeader, hunks: structuredPatch.hunks.map(hunk => {
7            return {
8                oldLines: hunk.newLines,
9                oldStart: hunk.newStart,
10                newLines: hunk.oldLines,
11                newStart: hunk.oldStart,
12                lines: hunk.lines.map(l => {
13                    if (l.startsWith('-')) {
14                        return `+${l.slice(1)}`;
15                    }
16                    if (l.startsWith('+')) {
17                        return `-${l.slice(1)}`;
18                    }
19                    return l;
20                })
21            };
22        }) });
23}
24 
codekingpro/portable-devtools · Team Ai