-
Notifications
You must be signed in to change notification settings - Fork 35
/
index.d.ts
47 lines (38 loc) · 1.48 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Type definitions for trie-search 2.0+
// Project: trie-search
// Definitions by: Joshua Jung
type KeyFields = string | KeyFields[]
type TrieSearchOptions<T> = {
indexField? : string
ignoreCase? : boolean
cache? : boolean
maxCacheSize? : number
splitOnRegEx? : RegExp | false
splitOnGetRegEx? : RegExp | false
min? : number
keepAll? : boolean
keepAllKey? : boolean
idFieldOrFunction? : string | ((item : T) => string)
expandRegexes? : { regex: RegExp, alternate : string }[]
insertFullUnsplitKey? : boolean
}
export default class TrieSearch<T> {
keyFields : KeyFields;
constructor(keyfields? : KeyFields | null, options? : TrieSearchOptions<T>);
add(item : T, customKeys? : KeyFields) : void
remove(phrase : string, keyFields? : KeyFields) : void
addAll(items : T[], customKeys? : KeyFields) : void
reset() : void
addFromObject(obj : any, valueField? : string) : void
map(key : string, value : T) : void
get(phraseOrPhrases : string | string[], reducer? : TrieSearch.ReducerFn<T> | null, limit? : number) : T[]
search(phrases : string | string[], reducer? : TrieSearch.ReducerFn<T>, limit? : number) : T[]
// Expected to be used internally only, but could be useful to someone someday
keyToArr(key : string) : string[]
clearCache() : void
root : any;
static UNION_REDUCER : TrieSearch.ReducerFn<any>
}
declare namespace TrieSearch {
export type ReducerFn<T> = (accumulator : T[], phrase : string, matches : T[], trieSearch : TrieSearch<T>) => T[]
}