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. |
| 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 | |
| 18 | export { getResults } |