How to use leven - 10 common examples

To help you get started, we’ve selected a few leven 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 mozilla / fathom / examples / readability.js View on Github external
compare(expectedDom, sourceDom) {
        // Currently, this is just a surrounding-whitespace-
        // insensitive comparison of the text content.
        const expectedText = collapseNewlines(trimLines(textContent(expectedDom)));
        const gotText = collapseNewlines(trimLines(this.contentFnodes(sourceDom).map(fnode => fnode.element.textContent).join('\n')));
        this.lengthOfExpectedTexts += expectedText.length;
        this.lengthOfDiffs += leven(expectedText, gotText);

        // Uncomment for debugging:
        // console.log('Got:\n' + gotText);
        // console.log('\nExpected:\n' + expectedText);
    }
github microsoft / pyright / server / src / common / stringUtils.ts View on Github external
}

    const symbolLower = symbolName.toLocaleLowerCase();
    const typedLower = typedValue.toLocaleLowerCase();

    if (symbolLower.startsWith(typedLower)) {
        return 0.75;
    }

    // How far apart are the two strings? Find the smallest edit
    // distance for each of the substrings taken from the start of
    // symbolName.
    let symbolSubstrLength = symbolLower.length;
    let smallestEditDistance = Number.MAX_VALUE;
    while (symbolSubstrLength > 0) {
        const editDistance = leven(symbolLower.substr(0, symbolSubstrLength), typedLower);
        if (editDistance < smallestEditDistance) {
            smallestEditDistance = editDistance;
        }
        symbolSubstrLength--;
    }

    // We'll take into account the length of the typed value. If the user
    // has typed more characters, and they largely match the symbol name,
    // it is considered more similar. If the the edit distance is similar
    // to the number of characters the user has typed, then there's almost
    // no similarity.
    if (smallestEditDistance >= typedValue.length) {
        return 0;
    }

    const similarity = (typedValue.length - smallestEditDistance) / typedValue.length;
github babel / babel / src / babel / transformation / transformers / validation / undeclared-variable-check.js View on Github external
if (binding && binding.kind === "type" && !this.parentPath.isFlow()) {
      throw this.errorWithNode(messages.get("undeclaredVariableType", node.name), ReferenceError);
    }

    if (scope.hasBinding(node.name)) return;

    // get the closest declaration to offer as a suggestion
    // the variable name may have just been mistyped

    var bindings = scope.getAllBindings();

    var closest;
    var shortest = -1;

    for (var name in bindings) {
      var distance = levenshtein(node.name, name);
      if (distance <= 0 || distance > 3) continue;
      if (distance <= shortest) continue;

      closest = name;
      shortest = distance;
    }

    var msg;
    if (closest) {
      msg = messages.get("undeclaredVariableSuggestion", node.name, closest);
    } else {
      msg = messages.get("undeclaredVariable", node.name);
    }

    //
github facebook / jest / packages / jest-validate / src / utils.ts View on Github external
const suggestion = allowedOptions.find(option => {
    const steps: number = leven(option, unrecognized);
    return steps < 3;
  });
github oliverschwendener / ueli / src / js / Helpers / StringHelpers.js View on Github external
getWeight(programNameWithExtension, userInput) {
        let results = []
        let stringToSearchWords = this.splitStringToArray(programNameWithExtension)
        let valueWords = this.splitStringToArray(userInput)

        for (let word of stringToSearchWords)
            for (let value of valueWords) {
                if (value.length === 0 || word.length === 0)
                    continue

                word = word.toLowerCase()
                value = value.toLowerCase()
                let levenshteinDistance = leven(word, value)
                let result = word.startsWith(value)
                    ? (levenshteinDistance / 4)
                    : levenshteinDistance

                results.push(result)
            }

        return this.getAvg(results)
    }
github foray1010 / didyoumean2 / src / index.ts View on Github external
scoreProcessor = (matchItem: T) =>
        leven(
          normalizedInput,
          matchItemProcessor(matchItem, optionsWithDefaults),
        )
      break
github atlassian / better-ajv-errors / src / validation-errors / enum.js View on Github external
.map(value => ({
        value,
        weight: leven(value, currentValue.toString()),
      }))
      .sort((x, y) =>
github stephank / castling.club / src / front / game.ts View on Github external
    const moves = sortBy([...game.moves()], move => leven(input, move))
      .slice(0, 5)
github sanity-io / sanity / packages / @sanity / desk-tool / src / utils / resolvePanes.js View on Github external
(acc, current) => {
          const distance = leven(current, key)
          return distance < 3 && distance < acc.distance ? {closest: current, distance} : acc
        },
        {closest: null, distance: +Infinity}

leven

Measure the difference between two strings using the Levenshtein distance algorithm

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular leven functions