Files
lucide/docs/.vitepress/theme/composables/useSearch.ts
Han Yeong-woo eb035fe370 Improve formatting (#1814)
* Ignore linting for examples in docs

* Formatting JSX single attribute per line

* Separte `format` and `lint:format` in package.json

* Bump prettier version

* Run format
2024-02-01 14:38:21 +01:00

30 lines
575 B
TypeScript

import Fuse from 'fuse.js';
import { shallowRef, computed, Ref } from 'vue';
const useSearch = <T>(
query: Ref<string>,
collection: Ref<T[]>,
keys: Fuse.FuseOptionKey<T>[] = [],
) => {
const index = shallowRef(
new Fuse(collection.value, {
threshold: 0.2,
keys,
}),
);
const results = computed(() => {
index.value.setCollection(collection.value);
if (query.value) {
return index.value.search(query.value).map((result) => result.item);
}
return collection.value;
});
return results;
};
export default useSearch;