mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-15 21:17:41 +01:00
* 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
30 lines
575 B
TypeScript
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;
|