mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-26 16:57:07 +08:00
fix(test): resolve I being replaced with i when english punctuation was enabled
closes #4763
This commit is contained in:
parent
79d1b354a9
commit
04077fac61
1 changed files with 20 additions and 2 deletions
|
|
@ -1,4 +1,7 @@
|
|||
import { randomElementFromArray } from "../utils/misc";
|
||||
import {
|
||||
capitalizeFirstLetterOfEachWord,
|
||||
randomElementFromArray,
|
||||
} from "../utils/misc";
|
||||
|
||||
type Pair = [string, string[]];
|
||||
|
||||
|
|
@ -54,6 +57,21 @@ export async function replace(word: string): Promise<string> {
|
|||
|
||||
return word.replace(
|
||||
RegExp(`^(?:([\\W]*)(${replacement[0]})([\\W]*))$`, "gi"),
|
||||
randomReplacement
|
||||
(_, $1, $2, $3) =>
|
||||
$1 +
|
||||
($2.charAt(0) === $2.charAt(0).toUpperCase()
|
||||
? shouldWholeReplacementWordBeCapitalised($2)
|
||||
? randomReplacement.toUpperCase()
|
||||
: capitalizeFirstLetterOfEachWord(randomReplacement)
|
||||
: randomReplacement) +
|
||||
$3
|
||||
);
|
||||
}
|
||||
|
||||
function shouldWholeReplacementWordBeCapitalised(
|
||||
wordToBeReplaced: string
|
||||
): boolean {
|
||||
if (wordToBeReplaced === "I") return false;
|
||||
if (wordToBeReplaced === wordToBeReplaced.toUpperCase()) return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue