mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-27 17:27:32 +08:00
impr: add backtick in javascript language when punctuation is enabled (ascodeasice) (#4801)
* refactor: logic for adding bracket in code language * feat: add tick-wrapped words in javascript * feat: add tick to javascript with punc
This commit is contained in:
parent
4b3059bdc7
commit
2f4eb103da
1 changed files with 15 additions and 9 deletions
|
|
@ -121,15 +121,17 @@ export async function punctuateWord(
|
|||
} else if (Math.random() < 0.012 && lastChar !== "," && lastChar !== ".") {
|
||||
if (currentLanguage === "code") {
|
||||
const r = Math.random();
|
||||
if (r < 0.25) {
|
||||
word = `(${word})`;
|
||||
} else if (r < 0.5) {
|
||||
word = `{${word}}`;
|
||||
} else if (r < 0.75) {
|
||||
word = `[${word}]`;
|
||||
} else {
|
||||
word = `<${word}>`;
|
||||
const brackets = ["()", "{}", "[]", "<>"];
|
||||
|
||||
// add `word` in javascript
|
||||
if (Config.language.startsWith("code_javascript")) {
|
||||
brackets.push("``");
|
||||
}
|
||||
|
||||
const index = Math.floor(r * brackets.length);
|
||||
const bracket = brackets[index];
|
||||
|
||||
word = `${bracket[0]}${word}${bracket[1]}`;
|
||||
} else {
|
||||
word = `(${word})`;
|
||||
}
|
||||
|
|
@ -227,7 +229,11 @@ export async function punctuateWord(
|
|||
) {
|
||||
word = Misc.randomElementFromArray(specialsC);
|
||||
} else {
|
||||
word = Misc.randomElementFromArray(specials);
|
||||
if (Config.language.startsWith("code_javascript")) {
|
||||
word = Misc.randomElementFromArray([...specials, "`"]);
|
||||
} else {
|
||||
word = Misc.randomElementFromArray(specials);
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
Math.random() < 0.5 &&
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue