fastest-levenshtein

repository·master·Indexed 20 days ago

https://github.com/ka-weihe/fastest-levenshtein

A high-performance JavaScript/TypeScript implementation of the Levenshtein distance algorithm for measuring the difference between two strings. Version 1.0.16 provides the distance() function to calculate edit distance and the closest() function to find the string with the lowest edit distance from an array.

Tokens
488
Snippets
3
Records
3
Agent score
23%

What's inside fastest-levenshtein

  1. Use fastest-levenshtein in Node.js

    master

    In a Node.js environment, import distance and closest using require.

    • distance(s1, s2): Returns the Levenshtein distance (the number of edits required to change one string into another) between two strings.
    • closest(s, arr): Returns the string from the provided array arr that has the lowest edit distance to the target string s.
    const {distance, closest} = require('fastest-levenshtein')
    
    // Print levenshtein-distance between 'fast' and 'faster' 
    console.log(distance('fast', 'faster'))
    //=> 2
    
    // Print string from array with lowest edit-distance to 'fast'
    console.log(closest('fast', ['slow', 'faster', 'fastest']))
    //=> 'faster'
  2. Use fastest-levenshtein in Deno

    master

    In Deno, import distance and closest directly from the remote URL:

    https://deno.land/x/fastest_levenshtein/mod.ts

    import {distance, closest} from 'https://deno.land/x/fastest_levenshtein/mod.ts'
    
    // Print levenshtein-distance between 'fast' and 'faster' 
    console.log(distance('fast', 'faster'))
    //=> 2
    
    // Print string from array with lowest edit-distance to 'fast'
    console.log(closest('fast', ['slow', 'faster', 'fastest']))
    //=> 'faster'