Pulled ALL skills from 15 source repositories: - anthropics/skills: 16 (docs, design, MCP, testing) - obra/superpowers: 14 (TDD, debugging, agents, planning) - coreyhaines31/marketingskills: 25 (marketing, CRO, SEO, growth) - better-auth/skills: 5 (auth patterns) - vercel-labs/agent-skills: 5 (React, design, Vercel) - antfu/skills: 16 (Vue, Vite, Vitest, pnpm, Turborepo) - Plus 13 individual skills from various repos Mosaic Stack is not limited to coding — the Orchestrator and subagents serve coding, business, design, marketing, writing, logistics, analysis, and more. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
108 lines
2.4 KiB
Markdown
108 lines
2.4 KiB
Markdown
---
|
|
category: '@Integrations'
|
|
---
|
|
|
|
# useFuse
|
|
|
|
Easily implement fuzzy search using a composable with [Fuse.js](https://github.com/krisk/fuse).
|
|
|
|
From the Fuse.js website:
|
|
|
|
> What is fuzzy searching?
|
|
>
|
|
> Generally speaking, fuzzy searching (more formally known as approximate string matching) is the technique of finding strings that are approximately equal to a given pattern (rather than exactly).
|
|
|
|
## Install Fuse.js as a peer dependency
|
|
|
|
### NPM
|
|
|
|
```bash
|
|
npm install fuse.js@^7
|
|
```
|
|
|
|
### Yarn
|
|
|
|
```bash
|
|
yarn add fuse.js
|
|
```
|
|
|
|
## Usage
|
|
|
|
```ts
|
|
import { useFuse } from '@vueuse/integrations/useFuse'
|
|
import { shallowRef } from 'vue'
|
|
|
|
const data = [
|
|
'John Smith',
|
|
'John Doe',
|
|
'Jane Doe',
|
|
'Phillip Green',
|
|
'Peter Brown',
|
|
]
|
|
|
|
const input = shallowRef('Jhon D')
|
|
|
|
const { results } = useFuse(input, data)
|
|
|
|
/*
|
|
* Results:
|
|
*
|
|
* { "item": "John Doe", "index": 1 }
|
|
* { "item": "John Smith", "index": 0 }
|
|
* { "item": "Jane Doe", "index": 2 }
|
|
*
|
|
*/
|
|
```
|
|
|
|
## Type Declarations
|
|
|
|
```ts
|
|
export type FuseOptions<T> = IFuseOptions<T>
|
|
export interface UseFuseOptions<T> {
|
|
fuseOptions?: FuseOptions<T>
|
|
resultLimit?: number
|
|
matchAllWhenSearchEmpty?: boolean
|
|
}
|
|
export declare function useFuse<DataItem>(
|
|
search: MaybeRefOrGetter<string>,
|
|
data: MaybeRefOrGetter<DataItem[]>,
|
|
options?: MaybeRefOrGetter<UseFuseOptions<DataItem>>,
|
|
): {
|
|
fuse: Ref<
|
|
{
|
|
search: <R = DataItem>(
|
|
pattern: string | Expression,
|
|
options?: FuseSearchOptions,
|
|
) => FuseResult<R>[]
|
|
setCollection: (
|
|
docs: readonly DataItem[],
|
|
index?: FuseIndex<DataItem> | undefined,
|
|
) => void
|
|
add: (doc: DataItem) => void
|
|
remove: (predicate: (doc: DataItem, idx: number) => boolean) => DataItem[]
|
|
removeAt: (idx: number) => void
|
|
getIndex: () => FuseIndex<DataItem>
|
|
},
|
|
| Fuse<DataItem>
|
|
| {
|
|
search: <R = DataItem>(
|
|
pattern: string | Expression,
|
|
options?: FuseSearchOptions,
|
|
) => FuseResult<R>[]
|
|
setCollection: (
|
|
docs: readonly DataItem[],
|
|
index?: FuseIndex<DataItem> | undefined,
|
|
) => void
|
|
add: (doc: DataItem) => void
|
|
remove: (
|
|
predicate: (doc: DataItem, idx: number) => boolean,
|
|
) => DataItem[]
|
|
removeAt: (idx: number) => void
|
|
getIndex: () => FuseIndex<DataItem>
|
|
}
|
|
>
|
|
results: ComputedRef<FuseResult<DataItem>[]>
|
|
}
|
|
export type UseFuseReturn = ReturnType<typeof useFuse>
|
|
```
|