blob: 310dbf87815b7460981030b5f8acb35489022b81 [file] [log] [blame]
PineaFana34d04b2023-01-03 22:05:42 +00001import Fuse from "fuse.js";
2
3function getResults(typed: string, options: string[]): string[] {
4 options = options.filter((option) => option.length <= 100); // thanks discord. 6000 character limit on slash command inputs but only 100 for autocomplete.
5 if (!typed)
6 return options
7 .slice(0, 25)
8 .sort()
9 // @ts-expect-error
10 const fuse = new Fuse(options, {
11 useExtendedSearch: true,
12 findAllMatches: true,
13 minMatchCharLength: typed.length > 3 ? 3 : typed.length,
14 }).search(typed);
15 return fuse.slice(0, 25).map((option: {item: string }) => option.item );
16}
17
18export { getResults }