fix(smartfuzzy): handle empty search strings safely and update tests for stricter TypeScript compatibility
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user