mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-07 11:30:24 +08:00
refactor: move function
This commit is contained in:
parent
4fbdaa0e6f
commit
527cd5b690
3 changed files with 30 additions and 25 deletions
|
|
@ -4,7 +4,7 @@ import * as ManualRestart from "../test/manual-restart-tracker";
|
|||
import * as TestLogic from "../test/test-logic";
|
||||
import * as ChallengeController from "../controllers/challenge-controller";
|
||||
import Config, * as UpdateConfig from "../config";
|
||||
import * as Misc from "../utils/misc";
|
||||
import * as Strings from "../utils/strings";
|
||||
import * as WordFilterPopup from "./word-filter";
|
||||
import * as Notifications from "../elements/notifications";
|
||||
import * as SavedTextsPopup from "./saved-texts";
|
||||
|
|
@ -277,7 +277,7 @@ function cleanUpText(): string[] {
|
|||
text = text.replace(/ +/gm, " ");
|
||||
text = text.replace(/( *(\r\n|\r|\n) *)/g, "\n ");
|
||||
if (state.removeFancyTypographyEnabled) {
|
||||
text = Misc.cleanTypographySymbols(text);
|
||||
text = Strings.cleanTypographySymbols(text);
|
||||
}
|
||||
|
||||
if (state.replaceNewlines !== "off") {
|
||||
|
|
|
|||
|
|
@ -179,29 +179,6 @@ export function escapeHTML(str: string): string {
|
|||
return str;
|
||||
}
|
||||
|
||||
export function cleanTypographySymbols(textToClean: string): string {
|
||||
const specials = {
|
||||
"“": '"', // “ “
|
||||
"”": '"', // ” ”
|
||||
"„": '"', // „ „
|
||||
"’": "'", // ‘ ‘
|
||||
"‘": "'", // ’ ’
|
||||
",": ",", // ‚ ‚
|
||||
"—": "-", // — —
|
||||
"…": "...", // … …
|
||||
"«": "<<",
|
||||
"»": ">>",
|
||||
"–": "-",
|
||||
" ": " ",
|
||||
" ": " ",
|
||||
" ": " ",
|
||||
};
|
||||
return textToClean.replace(
|
||||
/[“”’‘—,…«»–\u2007\u202F\u00A0]/g,
|
||||
(char) => specials[char as keyof typeof specials] || ""
|
||||
);
|
||||
}
|
||||
|
||||
export function isUsernameValid(name: string): boolean {
|
||||
if (name === null || name === undefined || name === "") return false;
|
||||
if (name.toLowerCase().includes("miodec")) return false;
|
||||
|
|
|
|||
|
|
@ -121,3 +121,31 @@ export function getLanguageDisplayString(
|
|||
export function removeLanguageSize(language: string): string {
|
||||
return language.replace(/_\d*k$/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes fancy typography symbols from a string.
|
||||
* @param textToClean
|
||||
* @returns Cleaned text.
|
||||
*/
|
||||
export function cleanTypographySymbols(textToClean: string): string {
|
||||
const specials = {
|
||||
"“": '"', // “ “
|
||||
"”": '"', // ” ”
|
||||
"„": '"', // „ „
|
||||
"’": "'", // ‘ ‘
|
||||
"‘": "'", // ’ ’
|
||||
",": ",", // ‚ ‚
|
||||
"—": "-", // — —
|
||||
"…": "...", // … …
|
||||
"«": "<<",
|
||||
"»": ">>",
|
||||
"–": "-",
|
||||
" ": " ",
|
||||
" ": " ",
|
||||
" ": " ",
|
||||
};
|
||||
return textToClean.replace(
|
||||
/[“”’‘—,…«»–\u2007\u202F\u00A0]/g,
|
||||
(char) => specials[char as keyof typeof specials] || ""
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue