mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-29 18:27:33 +08:00
fix: morse sometimes showing undefined
Fixed by replacing accented letter with their non-accented versions Closes #4526
This commit is contained in:
parent
cef9affb32
commit
acf84dd9a2
1 changed files with 10 additions and 2 deletions
|
|
@ -1640,8 +1640,11 @@ export function convertToMorse(word: string): string {
|
|||
|
||||
let morseWord = "";
|
||||
|
||||
for (let i = 0; i < word.length; i++) {
|
||||
morseWord += morseCode[word.toLowerCase()[i]] + "/";
|
||||
const deAccentedWord = replaceSpecialChars(word);
|
||||
console.log(deAccentedWord);
|
||||
for (let i = 0; i < deAccentedWord.length; i++) {
|
||||
const letter = morseCode[deAccentedWord.toLowerCase()[i]];
|
||||
morseWord += letter ? letter + "/" : "";
|
||||
}
|
||||
return morseWord;
|
||||
}
|
||||
|
|
@ -1652,4 +1655,9 @@ export function typedKeys<T extends object>(
|
|||
return Object.keys(obj) as unknown as T extends T ? (keyof T)[] : never;
|
||||
}
|
||||
|
||||
//https://ricardometring.com/javascript-replace-special-characters
|
||||
export function replaceSpecialChars(str: string): string {
|
||||
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); // Remove accents
|
||||
}
|
||||
|
||||
// DO NOT ALTER GLOBAL OBJECTSONSTRUCTOR, IT WILL BREAK RESULT HASHES
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue