diff --git a/types/fuzzy-search/fuzzy-search-tests.ts b/types/fuzzy-search/fuzzy-search-tests.ts new file mode 100644 index 0000000000..667cda446f --- /dev/null +++ b/types/fuzzy-search/fuzzy-search-tests.ts @@ -0,0 +1,27 @@ +import FuzzySearch = require('fuzzy-search'); + +const f = new FuzzySearch(['1', '2', '3']); + +new FuzzySearch([{ a: 1 }, { a: 2 }, { a: 3 }], ['a']); + +new FuzzySearch([{ a: 1 }, { a: 2 }, { a: 3 }], ['a'], {}); + +new FuzzySearch([{ a: 1 }, { a: 2 }, { a: 3 }], ['a'], { caseSensitive: true }); + +new FuzzySearch([{ a: 1 }, { a: 2 }, { a: 3 }], ['a'], { sort: true }); + +new FuzzySearch([{ a: 1 }, { a: 2 }, { a: 3 }], ['a'], { caseSensitive: true, sort: true }); + +let strArr: string[]; + +strArr = f.haystack; +// $ExpectType string[] +f.keys; +// $ExpectType Required +f.options; + +strArr = new FuzzySearch(['1', '2', '3']).search(); +strArr = new FuzzySearch(['1', '2', '3']).search('2'); + +// $ExpectType number +FuzzySearch.isMatch('1', '1', false); diff --git a/types/fuzzy-search/index.d.ts b/types/fuzzy-search/index.d.ts new file mode 100644 index 0000000000..8c3d5103ff --- /dev/null +++ b/types/fuzzy-search/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for fuzzy-search 2.1 +// Project: https://github.com/wouter2203/fuzzy-search#readme +// Definitions by: Alex Deas +// BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +declare class FuzzySearch { + haystack: T[]; + keys: string[]; + options: Required; + + static isMatch(item: string, query: string, caseSensitive: boolean): number; + + constructor(haystack: T[], keys?: string[], options?: FuzzySearch.Options); + search(needle?: string): T[]; +} + +declare namespace FuzzySearch { + interface Options { + caseSensitive?: boolean; + sort?: boolean; + } +} + +export = FuzzySearch; diff --git a/types/fuzzy-search/tsconfig.json b/types/fuzzy-search/tsconfig.json new file mode 100644 index 0000000000..c72f9609d0 --- /dev/null +++ b/types/fuzzy-search/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fuzzy-search-tests.ts" + ] +} diff --git a/types/fuzzy-search/tslint.json b/types/fuzzy-search/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fuzzy-search/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }