mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-08 19:20:05 +00:00
Add types for fuzzy-search
This commit is contained in:
27
types/fuzzy-search/fuzzy-search-tests.ts
Normal file
27
types/fuzzy-search/fuzzy-search-tests.ts
Normal 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
26
types/fuzzy-search/index.d.ts
vendored
Normal 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;
|
||||
23
types/fuzzy-search/tsconfig.json
Normal file
23
types/fuzzy-search/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/fuzzy-search/tslint.json
Normal file
1
types/fuzzy-search/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user