aboutsummaryrefslogtreecommitdiff
path: root/src/js/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/index.js')
-rw-r--r--src/js/index.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/js/index.js b/src/js/index.js
index 6f0da65..f3582b0 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -195,8 +195,16 @@
195 proper.push(part.toLowerCase()); 195 proper.push(part.toLowerCase());
196 } 196 }
197 } 197 }
198 // TODO some levenstein on the words
199 var properPhrase = proper.join(' '); 198 var properPhrase = proper.join(' ');
199 // Check each word
200 for (var i=0; i<proper.length; i++) {
201 var word = proper[i];
202 if (WORDLISTS["english"].indexOf(word) == -1) {
203 console.log("Finding closest match to " + word);
204 var nearestWord = findNearestWord(word);
205 return word + " not in wordlist, did you mean " + nearestWord + "?";
206 }
207 }
200 // Check the words are valid 208 // Check the words are valid
201 var isValid = mnemonic.check(properPhrase); 209 var isValid = mnemonic.check(properPhrase);
202 if (!isValid) { 210 if (!isValid) {
@@ -389,6 +397,21 @@
389 .show(); 397 .show();
390 } 398 }
391 399
400 function findNearestWord(word) {
401 var words = WORDLISTS["english"];
402 var minDistance = 99;
403 var closestWord = words[0];
404 for (var i=0; i<words.length; i++) {
405 var comparedTo = words[i];
406 var distance = Levenshtein.get(word, comparedTo);
407 if (distance < minDistance) {
408 closestWord = comparedTo;
409 minDistance = distance;
410 }
411 }
412 return closestWord;
413 }
414
392 function hidePending() { 415 function hidePending() {
393 DOM.feedback 416 DOM.feedback
394 .text("") 417 .text("")