feat(ObjectSorter): now sorts objects by likability
This commit is contained in:
26
ts/smartfuzzy.classes.objectsorter.ts
Normal file
26
ts/smartfuzzy.classes.objectsorter.ts
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user