deno.land / x / velociraptor@1.5.0 / src / did_you_mean.ts

did_you_mean.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { levenshtein } from "../deps.ts";
export function didYouMean(wrongStr: string, strings: string[]): string | null { const suggestion = strings.reduce((closest: any, name, index) => { const distance = levenshtein(wrongStr, name); if ( distance < wrongStr.length && (closest == null || distance < (<any> closest).distance) ) { return { index, distance }; } return closest; }, null); return suggestion ? strings[suggestion.index] : null;}
velociraptor

Version Info

Tagged at
2 years ago