mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-25 17:26:15 -04:00
refactor(search-bar): improved tool fuzzy search
This commit is contained in:
parent
8476cf319b
commit
1b5d4e72bd
4 changed files with 39 additions and 16 deletions
23
src/composable/fuzzySearch.ts
Normal file
23
src/composable/fuzzySearch.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { get, type MaybeRef } from '@vueuse/core';
|
||||
import Fuse from 'fuse.js';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export { useFuzzySearch };
|
||||
|
||||
function useFuzzySearch<Data>({
|
||||
search,
|
||||
data,
|
||||
options = {},
|
||||
}: {
|
||||
search: MaybeRef<string>;
|
||||
data: Data[];
|
||||
options?: Fuse.IFuseOptions<Data>;
|
||||
}) {
|
||||
const fuse = new Fuse(data, options);
|
||||
|
||||
const searchResult = computed(() => {
|
||||
return fuse.search(get(search)).map(({ item }) => item);
|
||||
});
|
||||
|
||||
return { searchResult };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue