mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-02-25 07:14:00 +08:00
Add minor optimization (#3294)
This commit is contained in:
parent
8f5f607da6
commit
0dd2539bf7
2 changed files with 10 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
import _ from "lodash";
|
||||
|
||||
// Sorry for the bad words
|
||||
const profanities = [
|
||||
export const profanities = [
|
||||
"miodec",
|
||||
"bitly",
|
||||
"niqqa",
|
||||
|
@ -431,4 +433,7 @@ const profanities = [
|
|||
"ass",
|
||||
];
|
||||
|
||||
export default profanities;
|
||||
export const regexProfanities = profanities.map((profanity) => {
|
||||
const normalizedProfanity = _.escapeRegExp(profanity.toLowerCase());
|
||||
return `${normalizedProfanity}.*`;
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import _ from "lodash";
|
||||
import profanities from "../constants/profanities";
|
||||
import { profanities, regexProfanities } from "../constants/profanities";
|
||||
import { matchesAPattern, sanitizeString } from "./misc";
|
||||
|
||||
export function inRange(value: number, min: number, max: number): boolean {
|
||||
|
@ -38,12 +38,9 @@ export function containsProfanity(text: string): boolean {
|
|||
return sanitizeString(str) ?? "";
|
||||
});
|
||||
|
||||
const hasProfanity = profanities.some((profanity) => {
|
||||
const normalizedProfanity = _.escapeRegExp(profanity.toLowerCase());
|
||||
const prefixedProfanity = `${normalizedProfanity}.*`;
|
||||
|
||||
const hasProfanity = regexProfanities.some((profanity) => {
|
||||
return normalizedText.some((word) => {
|
||||
return matchesAPattern(word, prefixedProfanity);
|
||||
return matchesAPattern(word, profanity);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue