Add additional patch methods in jsdiff

* Add `IUniDiff` struct, representing a unified diff
* Add `IHunk` struct, representing a section of modified lines and context
* Fix `createPatch` optional `options` argument
* Fix `applyPatch` to accept either a patch string, IUniDiff or IUniDiff array
* Add `createTwoFilesPatch`, `structuredPatch` and `applyPatches`
* Add test code for these new functions
This commit is contained in:
ScottSWu
2016-08-09 16:21:39 -07:00
parent 5ff2770b38
commit 2fb8651931
2 changed files with 70 additions and 3 deletions
+30 -2
View File
@@ -16,6 +16,22 @@ declare namespace JsDiff {
componenets: IDiffResult[];
}
interface IHunk {
oldStart: number;
oldLines: number;
newStart: number;
newLines: number;
lines: string[];
}
interface IUniDiff {
oldFileName: string;
newFileName: string;
oldHeader: string;
newHeader: string;
hunks: IHunk[];
}
class Diff {
ignoreWhitespace:boolean;
@@ -46,9 +62,21 @@ declare namespace JsDiff {
function diffCss(oldStr:string, newStr:string):IDiffResult[];
function createPatch(fileName:string, oldStr:string, newStr:string, oldHeader:string, newHeader:string):string;
function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;
function applyPatch(oldStr:string, uniDiff:string):string;
function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;
function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): IUniDiff;
function applyPatch(oldStr: string, uniDiff: string | IUniDiff | IUniDiff[]): string;
function applyPatches(uniDiff: IUniDiff[], options: {
loadFile: (index: number, callback: (err: Error, data: string) => void) => void,
patched: (index: number, content: string) => void,
complete: (err?: Error) => void
}): void;
function parsePatch(diffStr: string, options?: {strict: boolean}): IUniDiff[];
function convertChangesToXML(changes:IDiffResult[]):string;