From e234a5cc27d1fa4d3583523ebc173d5527e3c27f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 17 Feb 2024 01:04:25 -0800 Subject: fix(error): return partial match in closest --- src/lib/Error/path.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/lib') diff --git a/src/lib/Error/path.ts b/src/lib/Error/path.ts index 75c035d7..1e36268c 100644 --- a/src/lib/Error/path.ts +++ b/src/lib/Error/path.ts @@ -1,6 +1,10 @@ import levenshtein from 'fast-levenshtein'; export const closest = (path: string, suggestions: string[]) => { + const partialMatches = suggestions.filter((suggestion) => suggestion.includes(path)); + + if (partialMatches.length) return partialMatches[0]; + const suggestionsWithDistance = suggestions.map((suggestion) => { const distance = levenshtein.get(path, suggestion); -- cgit v1.2.3