fuzzyMatch

CommandPalette
stable

Score and filter an array of items against a fuzzy query string using a subsequence + positional scoring algorithm. Returns matched items sorted by descending score. An empty query returns all items with score 0.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

items
required
ReadonlyArray<T>
The full list of items to match against.
query
required
string
The search string. Matching is case-insensitive. Empty string returns all items.
getHaystack
required
(item: T) => { label: string, haystack: string }
Extractor function. "label" is used for display-quality scoring (prefix/word bonuses); "haystack" is the full searchable text for subsequence matching.

API

Return value

The value returned by this util.

Matched items wrapped in IFuzzyMatchResult { item, score }, sorted by score descending. Non-matching items are omitted.

Usage

Examples

Ready-to-paste usage snippets.

Filter a command list

typescript