Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
cbc72cd55b | |||
a2d8f9575d |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "smartfuzzy",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartfuzzy",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"private": false,
|
||||
"description": "fuzzy match strings against word dictionaries/arrays",
|
||||
"main": "dist/index.js",
|
||||
|
@ -34,7 +34,7 @@ export class Smartfuzzy {
|
||||
return dictionaryMap;
|
||||
}
|
||||
|
||||
getClosestMatchForString(stringArg: string) {
|
||||
getClosestMatchForString(stringArg: string): string {
|
||||
const fuseDictionary: { name: string }[] = [];
|
||||
for (const wordArg of this.dictionary) {
|
||||
fuseDictionary.push({
|
||||
@ -51,7 +51,11 @@ export class Smartfuzzy {
|
||||
keys: ['name']
|
||||
};
|
||||
const fuse = new plugins.fuseJs(fuseDictionary, fuseOptions);
|
||||
const result = fuse.search(stringArg);
|
||||
return result;
|
||||
const fuzzyResult = fuse.search(stringArg);
|
||||
let closestMatch: string = null;
|
||||
if(fuzzyResult.length > 0) {
|
||||
closestMatch = fuzzyResult[0].name;
|
||||
}
|
||||
return closestMatch;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user