Add minor optimization (#3294)

This commit is contained in:
Bruce Berrios 2022-07-03 09:57:09 -04:00 committed by GitHub
parent 8f5f607da6
commit 0dd2539bf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -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}.*`;
});

View file

@ -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);
});
});