diff options
Diffstat (limited to 'src/lib/components')
| -rw-r--r-- | src/lib/components/fuzzy-search.ts | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/components/fuzzy-search.ts b/src/lib/components/fuzzy-search.ts index 31597b0..ade48fe 100644 --- a/src/lib/components/fuzzy-search.ts +++ b/src/lib/components/fuzzy-search.ts @@ -5,19 +5,19 @@ export type FuzzyItem = { id: number; name: string }; export const FUZZ_LIMIT = 8; export const FUZZ_THRESHOLD = 0.2; -export type FuzzyMatch = KeyResult<FuzzyItem>; +export type FuzzyMatch<T extends FuzzyItem = FuzzyItem> = KeyResult<T>; /** Fuzzy-match `items` against `query`, ranked best-first. Empty/whitespace * query returns no matches. Results carry `.score`, `.target`, `.highlight()` * and `.obj` (the matched item). */ -export function matchItems( - items: FuzzyItem[], +export function matchItems<T extends FuzzyItem>( + items: T[], query: string, { limit = FUZZ_LIMIT, threshold = FUZZ_THRESHOLD, }: { limit?: number; threshold?: number } = {}, -): FuzzyMatch[] { +): FuzzyMatch<T>[] { const q = query.trim(); if (q === '') return []; const snap = fuzzysort.snapshot(items, { key: 'name' }); |
