Skip to content

Commit

Permalink
Merge pull request #10 from jaonoctus/fix/word-search
Browse files Browse the repository at this point in the history
fix: improve word search
  • Loading branch information
jaonoctus authored Jan 24, 2023
2 parents 9418fb5 + 7241ce1 commit 4d4e82e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async function askWord(index: number) {
name: 'word',
message: `Word [${index + 1}]:`,
source: searchWord,
default: 'bacon'
default: ''
},
])

Expand All @@ -133,6 +133,12 @@ async function askWord(index: number) {

function searchWord(_answersSoFar: any, input = '') {
return new Promise((resolve) => {
const wordsStartsWithInput = wordlist.filter((word) => word.startsWith(input))

if (Array.isArray(wordsStartsWithInput) && wordsStartsWithInput.length > 0) {
resolve(wordsStartsWithInput)
}

resolve(fuzzy.filter(input, wordlist).map((el) => el.original))
})
}
Expand Down

0 comments on commit 4d4e82e

Please sign in to comment.