mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-06 06:17:11 -04:00
23 lines
511 B
JavaScript
23 lines
511 B
JavaScript
![]() |
import { get } from '@vueuse/core';
|
||
|
import Fuse from 'fuse.js';
|
||
|
import { computed } from 'vue';
|
||
|
|
||
|
function useFuzzySearch({
|
||
|
search,
|
||
|
data,
|
||
|
options = {}
|
||
|
}) {
|
||
|
const fuse = new Fuse(data, options);
|
||
|
const filterEmpty = options.filterEmpty ?? true;
|
||
|
const searchResult = computed(() => {
|
||
|
const query = get(search);
|
||
|
if (!filterEmpty && query === "") {
|
||
|
return data;
|
||
|
}
|
||
|
return fuse.search(query).map(({ item }) => item);
|
||
|
});
|
||
|
return { searchResult };
|
||
|
}
|
||
|
|
||
|
export { useFuzzySearch as u };
|