(original: string, search: string)
| 9 | const BUFFER_LINES = 40 // Number of extra context lines to show before and after matches |
| 10 | |
| 11 | function getSimilarity(original: string, search: string): number { |
| 12 | // Empty searches are no longer supported |
| 13 | if (search === "") { |
| 14 | return 0 |
| 15 | } |
| 16 | |
| 17 | // Use the normalizeString utility to handle smart quotes and other special characters |
| 18 | const normalizedOriginal = normalizeString(original) |
| 19 | const normalizedSearch = normalizeString(search) |
| 20 | |
| 21 | if (normalizedOriginal === normalizedSearch) { |
| 22 | return 1 |
| 23 | } |
| 24 | |
| 25 | // Calculate Levenshtein distance using fastest-levenshtein's distance function |
| 26 | const dist = distance(normalizedOriginal, normalizedSearch) |
| 27 | |
| 28 | // Calculate similarity ratio (0 to 1, where 1 is an exact match) |
| 29 | const maxLength = Math.max(normalizedOriginal.length, normalizedSearch.length) |
| 30 | return 1 - dist / maxLength |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Performs a "middle-out" search of `lines` (between [startIndex, endIndex]) to find |
no test coverage detected