fix(smartfuzzy): handle empty search strings safely and update tests for stricter TypeScript compatibility
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartfuzzy',
|
||||
version: '1.1.10',
|
||||
version: '2.0.1',
|
||||
description: 'A library for fuzzy matching strings against word dictionaries or arrays, with support for object and article searching.'
|
||||
}
|
||||
|
||||
@@ -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