Compare the similarity of two strings in Javascript, Typescript and Php

One of the most common features that can be found on software applications is the possibility to perform text searches: A User types some arbitrary text and the application gives a list of results, somehow related to what the user was looking for. Based on this use case, efficient search engines must be able to find texts that fully or partially match the searched words and give relevant results to the user.

While searching for an exact string match on a database is a pretty straightforward task, getting fuzzy results (just like the user expects) requires a strategy to find similar texts by ignoring differences like letter case, accents or special characters which would prevent valid results from being obtained. In this scenario, having a good method to compare strings is a key feature.

The Levenshtein distance

The mathematical method that is commonly used as the base for string comparison is called Levenshtein distance. It is a string metric for measuring the difference between two sequences and is computed as a number which represents the minimum number of single-character edits (insertions, deletions or substitutions) that are required to change one of the strings into the other. Vladimir Levenshtein is the mathematician who considered this distance in 1965, and so the method received his name. String similarity comparison methods on the TurboCommons library use this method as the base for comparison calculations