@builder.io/dev-tools
Version:
Builder.io Visual CMS Devtools
35 lines (34 loc) • 1.7 kB
TypeScript
/**
* Fuzzy file matching utilities for file tree search.
* Provides VS Code-style fuzzy matching with substring support,
* match index calculation for highlighting, and scoring for ranking.
*/
/**
* Find the indices of fuzzy matched characters in the target string.
* Prioritizes matching in the filename first for filename-only queries.
* For path queries (containing "/"), tries to find contiguous matches first.
* Returns the indices where each query character was matched.
*/
export declare function findFuzzyMatchIndices(query: string, target: string): number[];
/**
* Match query characters within a specific range of the target string.
* Non-alphanumeric query characters that aren't found are skipped,
* matching the behavior of buildFuzzyPattern which converts them to wildcards.
*/
export declare function matchInRange(query: string, target: string, start: number, end: number): number[];
/**
* Calculate a score for fuzzy match quality (higher = better match).
* Prioritizes: exact filename matches, filename prefix matches, consecutive matches,
* word boundary matches, and shorter paths.
*/
export declare function calculateFuzzyMatchScore(query: string, filePath: string, matchIndices: number[]): number;
/**
* Convert a search query to a case-insensitive fuzzy glob pattern for ripgrep.
* Splits query at last "/" - path section uses tight matching (exact dirs),
* filename section uses typo-tolerant wildcards between chars.
*/
export declare function queryToFuzzyGlob(query: string): string;
/**
* Build a fuzzy pattern for a single segment (no path separators).
*/
export declare function buildFuzzyPattern(segment: string, typoTolerant: boolean): string;