smartfuzzy/ts/smartfuzzy.classes.objectsorter.ts

25 lines
672 B
TypeScript

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