blob: 50874a127f4e673bfb4ceab9be6db3163fd704d5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
import levenshtein from 'fast-levenshtein';
export const closest = (path: string, suggestions: string[]) => {
let closest = '';
let lowestDistance = Infinity;
suggestions.forEach((suggestion) => {
const distance = levenshtein.get(path, suggestion);
if (distance < lowestDistance) {
lowestDistance = distance;
closest = suggestion;
}
});
return closest;
};
|