PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 1 | import Fuse from "fuse.js"; |
| 2 | |
| 3 | function 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 Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 5 | if (!typed) return options.slice(0, 25).sort(); |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 6 | // @ts-expect-error |
| 7 | const fuse = new Fuse(options, { |
| 8 | useExtendedSearch: true, |
| 9 | findAllMatches: true, |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 10 | minMatchCharLength: typed.length > 3 ? 3 : typed.length |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 11 | }).search(typed); |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 12 | return fuse.slice(0, 25).map((option: { item: string }) => option.item); |
PineaFan | a34d04b | 2023-01-03 22:05:42 +0000 | [diff] [blame] | 13 | } |
| 14 | |
Skyler Grey | da16adf | 2023-03-05 10:22:12 +0000 | [diff] [blame] | 15 | export { getResults }; |