diff --git a/text/_util.ts b/text/_util.ts index 61e98b0f7002..e1d40cbce4fc 100644 --- a/text/_util.ts +++ b/text/_util.ts @@ -8,6 +8,6 @@ export function splitToWords(input: string) { export function capitalizeWord(word: string): string { return word - ? word[0].toLocaleUpperCase() + word.slice(1).toLocaleLowerCase() + ? word?.[0]?.toLocaleUpperCase() + word.slice(1).toLocaleLowerCase() : word; } diff --git a/text/closest_string.ts b/text/closest_string.ts index 6ae8983fc4b4..3d2575f4aa25 100644 --- a/text/closest_string.ts +++ b/text/closest_string.ts @@ -45,7 +45,7 @@ export function closestString( givenWord = givenWord.toLowerCase(); } - let nearestWord = possibleWords[0]; + let nearestWord = possibleWords[0]!; let closestStringDistance = Infinity; for (const each of possibleWords) { const distance = caseSensitive diff --git a/text/levenshtein_distance.ts b/text/levenshtein_distance.ts index 53d765ee91f2..fa324ae92581 100644 --- a/text/levenshtein_distance.ts +++ b/text/levenshtein_distance.ts @@ -27,19 +27,19 @@ export function levenshteinDistance(str1: string, str2: string): number { const char1 = str1[str1Index]; const char2 = str2[str2Index]; if (char1 === char2) { - tempDistances.push(distances[str1Index]); + tempDistances.push(distances[str1Index]!); } else { tempDistances.push( 1 + Math.min( - distances[str1Index], - distances[str1Index + 1], - tempDistances[tempDistances.length - 1], + distances[str1Index]!, + distances[str1Index + 1]!, + tempDistances.at(-1)!, ), ); } } distances = tempDistances; } - return distances[distances.length - 1]; + return distances.at(-1)!; }