fix(smartfuzzy): handle empty search strings safely and update tests for stricter TypeScript compatibility

This commit is contained in:
2026-05-01 16:02:29 +00:00
parent 58109bd7e0
commit 31c7865d88
12 changed files with 3676 additions and 4989 deletions
+5 -1
View File
@@ -118,6 +118,10 @@ export class Smartfuzzy {
return null; // Return null for empty dictionary instead of throwing error
}
if (stringArg.length === 0) {
return null;
}
const fuseDictionary: { name: string }[] = [];
for (const wordArg of this.dictionary) {
fuseDictionary.push({
@@ -135,7 +139,7 @@ export class Smartfuzzy {
};
const fuse = new plugins.fuseJs(fuseDictionary, fuseOptions);
const fuzzyResult = fuse.search(stringArg);
let closestMatch: string = null;
let closestMatch: string | null = null;
if (fuzzyResult.length > 0) {
closestMatch = fuzzyResult[0].item.name;
}