How to use js-levenshtein - 6 common examples

To help you get started, we’ve selected a few js-levenshtein examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prisma / photonjs / packages / photon-generate / archive / levenshtein-tests.ts View on Github external
import leven from 'js-levenshtein'

console.log(leven('first', 'first'), leven('first', 'mirst'), leven('first', 'asd'), leven('flase', 'false'))
github parcel-bundler / parcel / packages / core / utils / src / schema.js View on Github external
    .map(exp => [exp, levenshteinDistance(exp, actualValue)])
    .filter(
github vuejs / function-api-converter / src / converter / groups.js View on Github external
function getStatementGroupScore (nodeA, nodeB, variables) {
  const wordsA = getStatementWords(nodeA, variables)
  const wordsB = getStatementWords(nodeB, variables)
  let score = 0
  for (const wordA of wordsA) {
    for (const wordB of wordsB) {
      const distance = levenshtein(wordA.value, wordB.value)
      if (distance <= 1) {
        score += (wordA.score + wordB.score) / 2
      }
    }
  }
  return score
}
github ranyitz / qnm / src / suggest / get-suggestions.ts View on Github external
.map(opt => {
      return [opt, levenshtein(input, opt)] as [string, number];
    })
    .filter(([, distance]) => distance <= maxDistance)
github prisma / photonjs / packages / photon-generate / archive / benchmark-string-comparison.ts View on Github external
.add('levenshtein', () => {
    for (const word of words) {
      for (const word2 of words) {
        leven(word, word2)
      }
    }
  })
  .add('damerau levenshtein', () => {
github prisma / photonjs / packages / photon-generate / src / runtime / utils / common.ts View on Github external
(acc, curr) => {
      const distance = leven(str, curr)
      if (distance < acc.distance) {
        return {
          distance,
          str: curr,
        }
      }

      return acc
    },
    {

js-levenshtein

The most efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.

MIT
Latest version published 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular js-levenshtein functions