| Total Complexity | 13 |
| Complexity/F | 1.44 |
| Lines of Code | 44 |
| Function Count | 9 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | export function isWordInWordlist(word: string, wordlist: string[]): boolean { |
||
| 2 | const normalizedWord = word.trim().toLowerCase(); |
||
| 3 | if (!normalizedWord) return false; |
||
| 4 | |||
| 5 | return wordlist.some(w => w.toLowerCase() === normalizedWord); |
||
| 6 | } |
||
| 7 | |||
| 8 | export function getSuggestions(input: string, wordlist: string[], maxSuggestions: number = 10): string[] { |
||
| 9 | const normalizedInput = input.trim().toLowerCase(); |
||
| 10 | |||
| 11 | if (!normalizedInput) { |
||
| 12 | return []; |
||
| 13 | } |
||
| 14 | |||
| 15 | return wordlist.filter(word => word.toLowerCase().startsWith(normalizedInput)).slice(0, maxSuggestions); |
||
| 16 | } |
||
| 17 | |||
| 18 | export function getWordIndex(word: string, wordlist: string[]): number { |
||
| 19 | return wordlist.indexOf(word); |
||
| 20 | } |
||
| 21 | |||
| 22 | export function indexToBinaryValue(index: number): number { |
||
| 23 | return index + 1; |
||
| 24 | } |
||
| 25 | |||
| 26 | export function binaryValueToIndex(value: number): number { |
||
| 27 | return value - 1; |
||
| 28 | } |
||
| 29 | |||
| 30 | export function isValidIndex(index: number, wordlistLength: number): boolean { |
||
| 31 | return index >= 0 && index < wordlistLength; |
||
| 32 | } |
||
| 33 | |||
| 34 | export function getWordByIndex(index: number, wordlist: string[]): string | null { |
||
| 35 | if (!isValidIndex(index, wordlist.length)) { |
||
| 36 | return null; |
||
| 37 | } |
||
| 38 | return wordlist[index]; |
||
| 39 | } |
||
| 40 | |||
| 41 | export function shouldShowSuggestions(input: string, minLength: number = 1): boolean { |
||
| 42 | return input.trim().length >= minLength; |
||
| 43 | } |
||
| 44 |