mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-28 02:26:15 -04:00
24 lines
475 B
TypeScript
24 lines
475 B
TypeScript
![]() |
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 };
|
||
|
}
|