mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-28 08:43:07 +08:00
impr(typing): lazy mode now keeps the word casing
This commit is contained in:
parent
ecbc20f316
commit
9f05da905a
1 changed files with 30 additions and 8 deletions
|
@ -44,13 +44,35 @@ export function replaceAccents(
|
|||
word: string,
|
||||
accentsOverride?: MonkeyTypes.Accents
|
||||
): string {
|
||||
let newWord = word;
|
||||
if (!accents && !accentsOverride) return newWord;
|
||||
let regex;
|
||||
const list = accentsOverride || accents;
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
regex = new RegExp(`[${list[i][0]}]`, "gi");
|
||||
newWord = newWord.replace(regex, list[i][1]);
|
||||
if (!word) return word;
|
||||
|
||||
const accentMap = new Map(accentsOverride || accents);
|
||||
|
||||
const uppercased = word.toUpperCase();
|
||||
const cases = Array(word.length);
|
||||
|
||||
for (let i = 0; i < word.length; i++) {
|
||||
cases[i] = word[i] === uppercased[i] ? 1 : 0;
|
||||
}
|
||||
return newWord;
|
||||
|
||||
const newWordArray: string[] = [];
|
||||
|
||||
for (let i = 0; i < word.length; i++) {
|
||||
const char = word[i];
|
||||
if (accentMap.has(char)) {
|
||||
newWordArray.push(accentMap.get(char) as string);
|
||||
} else {
|
||||
newWordArray.push(char);
|
||||
}
|
||||
}
|
||||
|
||||
if (cases.includes(1)) {
|
||||
for (let i = 0; i < cases.length; i++) {
|
||||
if (cases[i] === 1) {
|
||||
newWordArray[i] = newWordArray[i].toUpperCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newWordArray.join("");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue