smartfuzzy/ts/smartfuzzy.classes.objectsorter.ts

25 lines
647 B
TypeScript
Raw Normal View History

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>[] {
const fuseOptions = {
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
2021-10-03 15:37:03 +00:00
keys: objectKeysArg,
};
2021-10-03 15:12:02 +00:00
const fuse = new plugins.fuseJs<T>(this.objectDictionary, fuseOptions);
const result = fuse.search(stringArg);
return result;
}
2021-10-03 15:37:03 +00:00
}