@zerospacegg/vynthra
Version:
Discord bot for ZeroSpace.gg data
49 lines • 1.38 kB
JavaScript
// Fuzzy string matching utilities using fuzzy
import fuzzy from "fuzzy";
/**
* Create a fuzzy matcher for a collection of strings
*/
export function createFuzzyMatcher(items, selector) {
return { items, selector };
}
/**
* Fuzzy search items with a query string
*/
export function fuzzySearch(matcher, query, limit = 10) {
const results = fuzzy.filter(query, matcher.items, {
extract: matcher.selector,
});
return results.slice(0, limit).map((result) => ({
item: result.original,
score: result.score,
positions: new Set(), // fuzzy package doesn't provide positions
}));
}
/**
* Check if a string contains another string (case insensitive)
*/
export function contains(query, target) {
if (query == null || target == null) {
return false;
}
return target.toLowerCase().includes(query.toLowerCase());
}
/**
* Check if target starts with query (case insensitive)
*/
export function startsWith(query, target) {
if (query == null || target == null) {
return false;
}
return target.toLowerCase().startsWith(query.toLowerCase());
}
/**
* Exact match check (case insensitive)
*/
export function exactMatch(query, target) {
if (query == null || target == null) {
return false;
}
return query.toLowerCase() === target.toLowerCase();
}
//# sourceMappingURL=fuzzy.js.map