Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(text): prepare for noUncheckedIndexedAccess #4148

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion text/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion text/closest_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions text/levenshtein_distance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)!;
}