blob: 5fce74f6a12f3652e4e90bd3b870fc0fda71a6e3 [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.
Skyler Greyda16adf2023-03-05 10:22:12 +00005 if (!typed) return options.slice(0, 25).sort();
PineaFana34d04b2023-01-03 22:05:42 +00006 // @ts-expect-error
7 const fuse = new Fuse(options, {
8 useExtendedSearch: true,
9 findAllMatches: true,
Skyler Greyda16adf2023-03-05 10:22:12 +000010 minMatchCharLength: typed.length > 3 ? 3 : typed.length
PineaFana34d04b2023-01-03 22:05:42 +000011 }).search(typed);
Skyler Greyda16adf2023-03-05 10:22:12 +000012 return fuse.slice(0, 25).map((option: { item: string }) => option.item);
PineaFana34d04b2023-01-03 22:05:42 +000013}
14
Skyler Greyda16adf2023-03-05 10:22:12 +000015export { getResults };