Download node_modules/@apideck/better-ajv-errors/src/lib/suggestions.ts from metarm/QMetaRam: direct link, hf CLI and curl.
- Browser
- Download file 665 Bytes
-
https://huggingface.co/metarm/QMetaRam/resolve/main/node_modules/%40apideck/better-ajv-errors/src/lib/suggestions.ts
- Command line
-
hf download hf://metarm/QMetaRam/node_modules/@apideck/better-ajv-errors/src/lib/suggestions.ts
-
curl -L -o suggestions.ts https://huggingface.co/metarm/QMetaRam/resolve/main/node_modules/%40apideck/better-ajv-errors/src/lib/suggestions.ts
665 Bytes
| import leven from 'leven'; | |
| export const getSuggestion = ({ | |
| value, | |
| suggestions, | |
| format = (suggestion) => `Did you mean '${suggestion}'?`, | |
| }: { | |
| value: string | null; | |
| suggestions: string[]; | |
| format?: (suggestion: string) => string; | |
| }): string => { | |
| if (!value) return ''; | |
| const bestSuggestion = suggestions.reduce( | |
| (best, current) => { | |
| const distance = leven(value, current); | |
| if (best.distance > distance) { | |
| return { value: current, distance }; | |
| } | |
| return best; | |
| }, | |
| { | |
| distance: Infinity, | |
| value: '', | |
| } | |
| ); | |
| return bestSuggestion.distance < value.length ? format(bestSuggestion.value) : ''; | |
| }; | |