mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 11:41:44 +00:00
Fuse definition changes (#13489)
* Changed the Namespace to Standard format (To upper case) * Added generic type parameters for Fuse * Added Export Statements to work with System Js setup * Added test to varify generic parameters
This commit is contained in:
+58
-1
@@ -67,7 +67,64 @@ function test_fuse_deep_key_search() {
|
||||
|
||||
var options = {
|
||||
keys: ['author.firstName']
|
||||
}
|
||||
};
|
||||
var f = new Fuse(books, options);
|
||||
var result = f.search('brwn');
|
||||
}
|
||||
|
||||
interface Book {
|
||||
id?: number;
|
||||
title?: string;
|
||||
author?: {firstName: string; lastName: string};
|
||||
}
|
||||
|
||||
function test_generic_fuse() {
|
||||
var books: Book[] = [{
|
||||
id: 1,
|
||||
title: 'The Great Gatsby',
|
||||
author: {
|
||||
firstName: 'F. Scott',
|
||||
lastName: 'Fitzgerald'
|
||||
}
|
||||
}, {
|
||||
title: 'The DaVinci Code',
|
||||
author: {
|
||||
firstName: 'Dan',
|
||||
lastName: 'Brown'
|
||||
}
|
||||
}];
|
||||
|
||||
var options = {
|
||||
keys: ["title", "author.firstName"]
|
||||
};
|
||||
var f = new Fuse<Book>(books, options);
|
||||
var result = f.search('brwn');
|
||||
}
|
||||
|
||||
function test_getFn() {
|
||||
var books = [{
|
||||
id: 1,
|
||||
title: 'The Great Gatsby',
|
||||
author: {
|
||||
firstName: 'F. Scott',
|
||||
lastName: 'Fitzgerald'
|
||||
}
|
||||
}, {
|
||||
title: 'The DaVinci Code',
|
||||
author: {
|
||||
firstName: 'Dan',
|
||||
lastName: 'Brown'
|
||||
}
|
||||
}];
|
||||
|
||||
var options = {
|
||||
keys: ["title", "author.firstName"],
|
||||
getFn: (obj: Book, path: string): string => {
|
||||
if (!obj) {
|
||||
return null;
|
||||
}
|
||||
return obj.author.firstName;
|
||||
}
|
||||
};
|
||||
var f = new Fuse<Book>(books, options);
|
||||
}
|
||||
|
||||
Vendored
+32
-8
@@ -3,22 +3,41 @@
|
||||
// Definitions by: Greg Smith <https://github.com/smrq/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class Fuse {
|
||||
constructor(list: any[], options?: fuse.IFuseOptions);
|
||||
search(pattern: string): any[];
|
||||
declare class Fuse<T> {
|
||||
constructor(list: T[], options?: Fuse.Options<T>);
|
||||
search(pattern: string): T[];
|
||||
}
|
||||
|
||||
declare namespace fuse {
|
||||
interface IFuseOptions {
|
||||
declare namespace Fuse {
|
||||
interface SearchFnConstructor {
|
||||
new (pattern: string, options?: SearchOptions): SearchFn;
|
||||
}
|
||||
|
||||
interface SearchFn {
|
||||
search(text: string): SearchResult;
|
||||
}
|
||||
|
||||
interface SearchResult {
|
||||
readonly isMatch: boolean;
|
||||
readonly score: number;
|
||||
}
|
||||
|
||||
interface SearchOptions {
|
||||
location?: number;
|
||||
distance?: number;
|
||||
threshold?: number;
|
||||
maxPatternLength?: number;
|
||||
}
|
||||
|
||||
interface Options<T> {
|
||||
id?: string;
|
||||
caseSensitive?: boolean;
|
||||
include?: string[];
|
||||
shouldSort?: boolean;
|
||||
searchFn?: any;
|
||||
searchFn?: SearchFnConstructor;
|
||||
sortFn?: (a: {score: number}, b: {score: number}) => number;
|
||||
getFn?: (obj: any, path: string) => any;
|
||||
keys?: string[] | { name:string; weight:number} [];
|
||||
verbose?:boolean;
|
||||
verbose?:boolean;
|
||||
tokenize?: boolean;
|
||||
tokenSeparator? : RegExp;
|
||||
matchAllTokens?: boolean;
|
||||
@@ -26,5 +45,10 @@ declare namespace fuse {
|
||||
distance?: number;
|
||||
threshold?: number;
|
||||
maxPatternLength?: number;
|
||||
includeScore?: boolean;
|
||||
getFn?: (obj: T, path: string) => string;
|
||||
}
|
||||
}
|
||||
|
||||
export = Fuse;
|
||||
export as namespace Fuse;
|
||||
|
||||
Reference in New Issue
Block a user