MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / fuzzyMatch

Function fuzzyMatch

src/utils/fuzzy.js:16–30  ·  view source on GitHub ↗
(candidate, query)

Source from the content-addressed store, hash-verified

14};
15
16export const fuzzyMatch = (candidate, query) => {
17 const lowerCandidate = (candidate || '').toLowerCase();
18 const lowerQuery = (query || '').toLowerCase();
19 if (!lowerQuery) return true;
20 if (lowerCandidate.includes(lowerQuery)) return true;
21 const candidateWords = lowerCandidate.split(/\s+/).filter(Boolean);
22 const queryWords = lowerQuery.split(/\s+/).filter(Boolean);
23 return queryWords.every(qw =>
24 candidateWords.some(cw => {
25 const distance = levenshtein(cw, qw);
26 const threshold = Math.max(1, Math.floor(qw.length / 3));
27 return distance <= threshold;
28 })
29 );
30};

Callers 3

ComponentListFunction · 0.90
searchComponentsFunction · 0.90
searchComponentsFunction · 0.90

Calls 1

levenshteinFunction · 0.85

Tested by

no test coverage detected