2018-08-19 18:52:52 +00:00
|
|
|
import * as plugins from './smartfuzzy.plugins';
|
|
|
|
|
|
|
|
export class ObjectSorter<T> {
|
|
|
|
public objectDictionary: T[];
|
|
|
|
|
|
|
|
|
|
|
|
constructor(objectDictionaryArg: T[] = []) {
|
|
|
|
this.objectDictionary = objectDictionaryArg;
|
|
|
|
}
|
|
|
|
|
2021-10-03 15:12:02 +00:00
|
|
|
sort(stringArg: string, objectKeysArg: string[]): plugins.fuseJs.FuseResult<T>[] {
|
2018-08-19 18:52:52 +00:00
|
|
|
const fuseOptions = {
|
|
|
|
shouldSort: true,
|
|
|
|
threshold: 0.6,
|
|
|
|
location: 0,
|
|
|
|
distance: 100,
|
|
|
|
maxPatternLength: 32,
|
|
|
|
minMatchCharLength: 1,
|
|
|
|
keys: objectKeysArg
|
|
|
|
};
|
2021-10-03 15:12:02 +00:00
|
|
|
const fuse = new plugins.fuseJs<T>(this.objectDictionary, fuseOptions);
|
2018-08-19 18:52:52 +00:00
|
|
|
const result = fuse.search(stringArg);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|