Levenshtein Typings [Types-2.0] (#11965)

* Adding Levenshtein typings

* Strict null checks on levenshtein
This commit is contained in:
Joshua DeVinney
2016-10-28 09:22:49 -05:00
committed by Masahiro Wakame
parent e579770198
commit 973846f739
3 changed files with 81 additions and 0 deletions

47
levenshtein/index.d.ts vendored Normal file
View File

@@ -0,0 +1,47 @@
// Type definitions for levenshtein v1.0
// Project: https://github.com/gf3/Levenshtein
// Definitions by: Joshua DeVinney <https://github.com/geoffreak>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Levenshtein {
/**
* Levenshtein string difference
* @param m First string
* @param n Second string
*/
constructor(m: string, n: string);
/**
* Distance between strings
*/
distance: number;
/**
* Distance between strings
* Alias of distance
*/
valueOf(): number;
/**
* Pretty print Levenshtein table.
*/
inspect(): string;
/**
* Pretty print Levenshtein table.
* Alias of inspect()
*/
toString(): string;
/**
* Return the Levenshtein table.
*/
getMatrix(): number[][];
}
// Required to make import as syntax work
declare namespace Levenshtein {
}
export = Levenshtein;

View File

@@ -0,0 +1,15 @@
import * as Levenshtein from 'levenshtein';
// Using standard methods
let l1 = new Levenshtein('kitten', 'sitting');
let num1: number = l1.distance;
let str1: string = l1.inspect();
// Using alias methods
let l2 = new Levenshtein('Saturday', 'Sunday');
let num2: number = l2.valueOf();
let str2: string = l2.toString();
// Levenshtein matrix can be retrieved
let l3 = new Levenshtein('kitten', 'sitting');
l3.getMatrix()[0].length;

19
levenshtein/tsconfig.json Normal file
View File

@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"levenshtein-tests.ts"
]
}