mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
diff: add support options parameter of diffLines (#16333)
* diff: add support options parameter of diffLines The options parameter is described at https://github.com/kpdecker/jsdiff/blob/master/README.md * diff: add tslint.json and fix lint issues
This commit is contained in:
parent
fef536fb65
commit
11b7768836
@ -1,13 +1,11 @@
|
||||
|
||||
|
||||
// tslint:disable:no-var only-arrow-functions
|
||||
import jsdiff = require('diff');
|
||||
|
||||
var one = 'beep boop';
|
||||
var other = 'beep boob blah';
|
||||
|
||||
var diff = jsdiff.diffChars(one, other);
|
||||
|
||||
diff.forEach(function (part) {
|
||||
diff.forEach(function(part) {
|
||||
var mark = part.added ? '+' :
|
||||
part.removed ? '-' : ' ';
|
||||
console.log(mark + " " + part.value);
|
||||
@ -16,11 +14,11 @@ diff.forEach(function (part) {
|
||||
// --------------------------
|
||||
|
||||
class LineDiffWithoutWhitespace extends jsdiff.Diff {
|
||||
tokenize(value:string):any {
|
||||
tokenize(value: string): any {
|
||||
return value.split(/^/m);
|
||||
}
|
||||
|
||||
equals(left:string, right:string):boolean {
|
||||
equals(left: string, right: string): boolean {
|
||||
return left.trim() === right.trim();
|
||||
}
|
||||
}
|
||||
@ -29,8 +27,8 @@ var obj = new LineDiffWithoutWhitespace(true);
|
||||
var diff = obj.diff(one, other);
|
||||
printDiff(diff);
|
||||
|
||||
function printDiff(diff:jsdiff.IDiffResult[]) {
|
||||
function addLineHeader(decorator:string, str:string) {
|
||||
function printDiff(diff: jsdiff.IDiffResult[]) {
|
||||
function addLineHeader(decorator: string, str: string) {
|
||||
return str.split("\n").map((line, index, array) => {
|
||||
if (index === array.length - 1 && line === "") {
|
||||
return line;
|
||||
@ -40,7 +38,7 @@ function printDiff(diff:jsdiff.IDiffResult[]) {
|
||||
}).join("\n");
|
||||
}
|
||||
|
||||
diff.forEach((part)=> {
|
||||
diff.forEach((part) => {
|
||||
if (part.added) {
|
||||
console.log(addLineHeader("+", part.value));
|
||||
} else if (part.removed) {
|
||||
|
||||
44
types/diff/index.d.ts
vendored
44
types/diff/index.d.ts
vendored
@ -1,7 +1,8 @@
|
||||
// Type definitions for diff
|
||||
// Type definitions for diff 3.2
|
||||
// Project: https://github.com/kpdecker/jsdiff
|
||||
// Definitions by: vvakame <https://github.com/vvakame/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export = JsDiff;
|
||||
export as namespace JsDiff;
|
||||
@ -36,34 +37,37 @@ declare namespace JsDiff {
|
||||
}
|
||||
|
||||
class Diff {
|
||||
ignoreWhitespace:boolean;
|
||||
ignoreWhitespace: boolean;
|
||||
|
||||
constructor(ignoreWhitespace?:boolean);
|
||||
constructor(ignoreWhitespace?: boolean);
|
||||
|
||||
diff(oldString:string, newString:string):IDiffResult[];
|
||||
diff(oldString: string, newString: string): IDiffResult[];
|
||||
|
||||
pushComponent(components:IDiffResult[], value:string, added:boolean, removed:boolean):void;
|
||||
pushComponent(components: IDiffResult[], value: string, added: boolean, removed: boolean): void;
|
||||
|
||||
extractCommon(basePath:IBestPath, newString:string, oldString:string, diagonalPath:number):number;
|
||||
extractCommon(basePath: IBestPath, newString: string, oldString: string, diagonalPath: number): number;
|
||||
|
||||
equals(left:string, right:string):boolean;
|
||||
equals(left: string, right: string): boolean;
|
||||
|
||||
join(left:string, right:string):string;
|
||||
join(left: string, right: string): string;
|
||||
|
||||
tokenize(value:string):any; // return types are string or string[]
|
||||
tokenize(value: string): any; // return types are string or string[]
|
||||
}
|
||||
|
||||
function diffChars(oldStr:string, newStr:string):IDiffResult[];
|
||||
function diffChars(oldStr: string, newStr: string): IDiffResult[];
|
||||
|
||||
function diffWords(oldStr:string, newStr:string):IDiffResult[];
|
||||
function diffWords(oldStr: string, newStr: string): IDiffResult[];
|
||||
|
||||
function diffWordsWithSpace(oldStr:string, newStr:string):IDiffResult[];
|
||||
function diffWordsWithSpace(oldStr: string, newStr: string): IDiffResult[];
|
||||
|
||||
function diffJson(oldObj: Object, newObj: Object): IDiffResult[];
|
||||
function diffJson(oldObj: object, newObj: object): IDiffResult[];
|
||||
|
||||
function diffLines(oldStr:string, newStr:string):IDiffResult[];
|
||||
function diffLines(oldStr: string, newStr: string, options?: {
|
||||
ignoreWhitespace?: boolean,
|
||||
newlineIsToken?: boolean,
|
||||
}): IDiffResult[];
|
||||
|
||||
function diffCss(oldStr:string, newStr:string):IDiffResult[];
|
||||
function diffCss(oldStr: string, newStr: string): IDiffResult[];
|
||||
|
||||
function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string;
|
||||
|
||||
@ -74,14 +78,14 @@ declare namespace JsDiff {
|
||||
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
|
||||
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;
|
||||
function convertChangesToXML(changes: IDiffResult[]): string;
|
||||
|
||||
function convertChangesToDMP(changes:IDiffResult[]):{0: number; 1:string;}[];
|
||||
function convertChangesToDMP(changes: IDiffResult[]): Array<{0: number; 1: string; }>;
|
||||
}
|
||||
|
||||
7
types/diff/tslint.json
Normal file
7
types/diff/tslint.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"interface-name": false,
|
||||
"export-just-namespace": false
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user