Add types for fast-diff

This commit is contained in:
John Renner 2017-07-18 16:15:06 -07:00
parent d2bf223394
commit 2a92293a59
4 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import fastDiff = require('fast-diff');
let diffs: fastDiff.Diff[];
diffs = fastDiff("hi there", "hi");
diffs = fastDiff("hi there", "hi", 1);
diffs.forEach((diff: fastDiff.Diff) => {
const operation: number = diff[0];
const text: string = diff[1];
switch (diff[0]) {
case fastDiff.DIFF_EQUAL: break;
case fastDiff.DIFF_DELETE: break;
case fastDiff.DIFF_INSERT: break;
}
});

16
types/fast-diff/index.d.ts vendored Normal file
View File

@ -0,0 +1,16 @@
// Type definitions for fast-diff 1.1
// Project: https://github.com/jhchen/fast-diff#readme
// Definitions by: John Renner <https://github.com/djrenren>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare function diff(text1: string, text2: string, cursorPos?: number): diff.Diff[];
declare namespace diff {
type Diff = [-1 | 0 | 1, string];
const DIFF_DELETE: -1;
const DIFF_INSERT: 1;
const DIFF_EQUAL: 0;
}
export = diff;

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"fast-diff-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }