diff options
| author | Fuwn <[email protected]> | 2024-01-08 15:27:28 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-01-08 15:27:28 -0800 |
| commit | 6620bc00fdf5173ffb20a9057a4580b59410dbd7 (patch) | |
| tree | 57f149d20ce28960909bda1bba1d6fcbbd0ef515 /src/lib/Error | |
| parent | fix(badges): loading order (diff) | |
| download | due.moe-6620bc00fdf5173ffb20a9057a4580b59410dbd7.tar.xz due.moe-6620bc00fdf5173ffb20a9057a4580b59410dbd7.zip | |
feat(tools): new tools url method
Diffstat (limited to 'src/lib/Error')
| -rw-r--r-- | src/lib/Error/path.ts | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/lib/Error/path.ts b/src/lib/Error/path.ts index f493726b..40f50b7c 100644 --- a/src/lib/Error/path.ts +++ b/src/lib/Error/path.ts @@ -1,17 +1,11 @@ -import levenshtein from 'fast-levenshtein'; - export const closest = (path: string, suggestions: string[]) => { - let closest = ''; - let lowestDistance = Infinity; + const partialMatch = suggestions.find((suggestion) => suggestion.includes(path)); - [...suggestions, '...'].forEach((suggestion) => { - const distance = levenshtein.get(path, suggestion); + if (partialMatch) return partialMatch; - if (distance < lowestDistance) { - lowestDistance = distance; - closest = suggestion; - } - }); + const closestMatch = suggestions.reduce((prev, curr) => { + return prev.length > curr.length ? prev : curr; + }, ''); - return closest; + return closestMatch; }; |