fuzzy-matching
Fuzzy string matcher
Installation
npm install fuzzy-matching
Code sample
var FuzzyMatching = ; var fm = 'tough' 'thought' 'through' 'Café'; // Finds wordsconsole; // --> { distance: 1, value: 'tough' } // Finds words that are spelled wrong by looking at the closest ressembling wordconsole; // --> { distance: 0.7142857142857143, value: 'thought' }// Beware when words in your dictionary are very closeconsole; // --> { distance: 0.875, value: 'through' }, // though you may have wanted to get 'thought' // Case insensitiveconsole; // --> through // Accent-proofconsole; // --> Café // Add words after creationconsole; // --> { distance: 0, value: null } // because too remote to anything in the dictionaryfm;console; // --> { distance: 1, value: 'dinosaur' } // Want to limit to a certain degree of resemblance?console; // --> nullconsole; // --> tough
Use case: quizzes or user inputs with certain expected answers
var FuzzyMatching = ; var possibleAnswers = 'Jupiter' 'Mercury' 'Venus' 'Earth' fm = possibleAnswers answer = 'Mercury'; console; // Some user stuff... var userAnswer = 'mercuyr';var correctedAnswer = fmvalue;if answer === correctedAnswer console; else console;