feat(ObjectSorter): now sorts objects by likability

This commit is contained in:
2018-08-19 20:52:52 +02:00
parent fdf9ec6358
commit dc856dd5c7
4 changed files with 56 additions and 8 deletions

View File

@@ -0,0 +1,26 @@
import * as plugins from './smartfuzzy.plugins';
export class ObjectSorter<T> {
public objectDictionary: T[];
constructor(objectDictionaryArg: T[] = []) {
this.objectDictionary = objectDictionaryArg;
}
sort(stringArg: string, objectKeysArg: string[]): T[] {
const fuseOptions = {
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: objectKeysArg
};
const fuse = new plugins.fuseJs(this.objectDictionary, fuseOptions);
const result = fuse.search(stringArg);
return result;
}
}