Work on compose

This commit is contained in:
Jon Staab
2024-08-22 16:16:35 -07:00
parent 91fbc260eb
commit dc4dcb1ea2
12 changed files with 159 additions and 129 deletions
+8 -1
View File
@@ -38,7 +38,14 @@ export type SearchOptions<V, T> = {
sortFn?: (items: FuseResult<T>) => any
}
export const createSearch = <V, T>(data: T[], opts: SearchOptions<V, T>) => {
export type Search<V, T> = {
getValue: (item: T) => V
getOption: (value: V) => T | undefined
searchOptions: (term: string) => T[]
searchValues: (term: string) => V[]
}
export const createSearch = <V, T>(data: T[], opts: SearchOptions<V, T>): Search<V, T> => {
const fuse = new Fuse(data, {...opts.fuseOptions, includeScore: true})
const map = new Map<V, T>(data.map(item => [opts.getValue(item), item]))