
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
fuzzy-matching
Advanced tools
Fuzzy string matcher
npm install fuzzy-matching
var FuzzyMatching = require('fuzzy-matching');
var fm = new FuzzyMatching(['tough', 'thought', 'through', 'Café']);
// Finds words
console.log(fm.get('tough')); // --> { distance: 1, value: 'tough' }
// Finds words that are spelled wrong by looking at the closest ressembling word
console.log(fm.get('thouhgt')); // --> { distance: 0.7142857142857143, value: 'thought' }
// Beware when words in your dictionary are very close
console.log(fm.get('throught')); // --> { distance: 0.875, value: 'through' },
// though you may have wanted to get 'thought'
// Case insensitive
console.log(fm.get('ThRouHg').value); // --> through
// Accent-proof
console.log(fm.get('cafe').value); // --> Café
// Add words after creation
console.log(fm.get('dinosaur')); // --> { distance: 0, value: null }
// because too remote to anything in the dictionary
fm.add('dinosaur');
console.log(fm.get('dinosaur')); // --> { distance: 1, value: 'dinosaur' }
// Want to limit to a certain degree of resemblance?
console.log(fm.get('touch', { maxChanges: 0 }).value); // --> null
console.log(fm.get('touch', { maxChanges: 1 }).value); // --> tough
var FuzzyMatching = require('fuzzy-matching');
var possibleAnswers = ['Jupiter', 'Mercury', 'Venus', 'Earth'],
fm = new FuzzyMatching(possibleAnswers),
answer = 'Mercury';
console.log('Which planet is the closest to the Sun: ' + possibleAnswers.join(', ') + '?');
// Some user stuff...
var userAnswer = 'mercuyr';
var correctedAnswer = fm.get(userAnswer, { maxChanges: 2 }).value;
if (answer === correctedAnswer) {
console.log('That\'s right!, it\'s ' + answer + '!');
} else {
console.log('Sorry buddy, the answer was ' + answer + '.');
}
FAQs
Fuzzy string matcher
The npm package fuzzy-matching receives a total of 3,107 weekly downloads. As such, fuzzy-matching popularity was classified as popular.
We found that fuzzy-matching demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.