Add types for fuzzy-search

This commit is contained in:
Dimitri Benin
2018-12-02 19:38:23 +01:00
parent efbcbdebaf
commit 4e89119770
4 changed files with 77 additions and 0 deletions

View File

@@ -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<Options>
f.options;
strArr = new FuzzySearch(['1', '2', '3']).search();
strArr = new FuzzySearch(['1', '2', '3']).search('2');
// $ExpectType number
FuzzySearch.isMatch('1', '1', false);

26
types/fuzzy-search/index.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
// Type definitions for fuzzy-search 2.1
// Project: https://github.com/wouter2203/fuzzy-search#readme
// Definitions by: Alex Deas <https://github.com/alex-deas>
// BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
declare class FuzzySearch<T extends object | string> {
haystack: T[];
keys: string[];
options: Required<FuzzySearch.Options>;
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;

View File

@@ -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"
]
}

View File

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