prompt-bouncer
Version:
A lightweight, customizable content moderation library for AI applications. Filters profanity, explicit content, and inappropriate prompts for text-to-image generation.
1,043 lines • 26.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCategoryNames = exports.getKeywordsBySeverityLevels = exports.getCategoriesUpToSeverity = exports.getCategoriesBySeverity = exports.getAllKeywordsWithVariants = exports.ADDITIONAL_VARIANTS = exports.getKeywordsByCategory = exports.getAllKeywords = exports.DETECTION_CATEGORIES = void 0;
/**
* Built-in detection categories with curated word lists
*/
exports.DETECTION_CATEGORIES = {
mild: {
name: "mild",
severity: "low",
description: "Mild swearing and light offensive language, including fantasy/gaming terms",
keywords: [
"damn",
"damned",
"dammit",
"hell",
"hellish",
"crap",
"crappy",
"piss",
"pissed",
"suck",
"sucks",
"sucked",
"sucky",
"stupid",
"idiot",
"moron",
"dumb",
"dumbass",
"jerk",
"jerkoff",
"loser",
"freak",
"weirdo",
"creep",
"bloody",
"blimey",
"bugger",
"bollocks",
"fanny",
"arse",
"git",
"sod",
"turd",
"poop",
"fart",
"farted",
"farting",
// Fantasy/gaming/creative terms that could be legitimate
"sword",
"knife",
"blade",
"dagger",
"weapon",
"gun",
"rifle",
"pistol",
"bow",
"arrow",
"shield",
"armor",
"blood",
"death",
"kill", // could be "kill the bug" or gaming context
"attack",
"fight",
"battle",
"war",
"warfare",
"combat",
"destroy",
"shoot",
"fire", // as in "fire the weapon"
"explosive",
"bomb", // could be "bomb design" or gaming
"grenade",
"missile",
"rocket",
"laser",
"magic",
"spell",
"curse",
"hex",
"demon",
"monster",
"zombie",
"vampire",
"ghost",
"spirit",
"dark",
"shadow",
"evil",
// Moved from profanity - milder terms
"ass", // could be "badass" or donkey
"gay", // legitimate identity term
"dick", // could be a name
"fart", // natural bodily function
"crap", // already in mild but removing from profanity
"crappy", // already in mild but removing from profanity
// Moved from explicit - general terms that could be legitimate
"adult", // could refer to mature themes in games/movies
"sexy", // common descriptor
// Moved from drugs - general terms
"weed", // could refer to garden weeds
"pot", // cooking pot
"grass", // lawn grass
"herb", // cooking herb
],
},
profanity: {
name: "profanity",
severity: "medium",
description: "Strong profanity and offensive language",
keywords: [
"ahole",
"ash0le",
"ash0les",
"asholes",
"assface",
"assh0le",
"assh0lez",
"asshole",
"assholes",
"assholz",
"asswipe",
"azzhole",
"bassterds",
"bastard",
"bastards",
"bastardz",
"basterds",
"basterdz",
"biatch",
"bitch",
"bitches",
"bitchy",
"bitching",
"butthole",
"buttwipe",
"c0ck",
"c0cks",
"c0k",
"cawk",
"cawks",
"cock",
"cockhead",
"cock-head",
"cocks",
"cocksucker",
"cock-sucker",
"crapping", // kept this as it's more crude
"cunt",
"cunts",
"cuntz",
"dicks",
"dickhead",
"fag",
"fag1t",
"faget",
"fagg1t",
"faggit",
"faggot",
"fagit",
"fags",
"fagz",
"faig",
"faigs",
"fcuk",
"fuck",
"fucker",
"fuckers",
"fuckin",
"fucking",
"fucked",
"fucks",
"fuk",
"fukah",
"fuken",
"fuker",
"fukin",
"fukk",
"fukkah",
"fukken",
"fukker",
"fukkin",
"fux0r",
"gayboy", // kept as potentially derogatory
"gaygirl", // kept as potentially derogatory
"gayz", // kept as potentially derogatory
"goddamn",
"goddamned",
"god-damned",
"h00r",
"h0ar",
"h0re",
"hells",
"hoar",
"hoor",
"hoore",
"jackass",
"jackoff",
"jerk-off",
"knob",
"knobs",
"knobz",
"kunt",
"kunts",
"kuntz",
"motha fucker",
"motha fuker",
"motha fukkah",
"motha fukker",
"mother fucker",
"mother fukah",
"mother fuker",
"mother fukkah",
"mother fukker",
"mother-fucker",
"motherfucker",
"motherfuckers",
"motherfucking",
"mutha fucker",
"mutha fukah",
"mutha fuker",
"mutha fukkah",
"mutha fukker",
"pecker",
"phuc",
"phuck",
"phuk",
"phuker",
"phukker",
"prick",
"pussy",
"pussies",
"pusse",
"pussee",
"queer", // kept as can be derogatory when used as slur
"queers",
"queerz",
"qweers",
"qweerz",
"qweir",
"retard", // definitely offensive
"scank",
"schlong",
"shit",
"shits",
"shitter",
"shitty",
"shity",
"shitz",
"sh1t",
"sh1ter",
"sh1ts",
"sh1tter",
"sh1tz",
"shyt",
"shyte",
"shytty",
"shyty",
"skanck",
"skank",
"skankee",
"skankey",
"skanks",
"skanky",
"slut",
"sluts",
"slutty",
"slutz",
"son-of-a-bitch",
"twat",
"wh00r",
"wh0re",
"whore",
"whores",
"b!+ch",
"b17ch",
"b1tch",
"bi+ch",
"b!tch",
"bullshit",
"fatass",
"mofo",
"nutsack",
"smut",
"wank",
"whoar",
],
},
explicit: {
name: "explicit",
severity: "high",
description: "Highly sexually explicit content and pornography",
keywords: [
"nsfw",
"explicit",
"sex",
"porn",
"p0rn",
"pr0n",
"erotic",
"sexual",
"xxx",
"xrated",
"seductive",
"revealing",
"topless",
"underwear",
"lingerie",
"bikini",
"exposed",
"masturbation",
"masturbate",
"masterbat",
"masterbate",
"masterbates",
"massterbait",
"masstrbait",
"masstrbate",
"masterbaiter",
"nude",
"naked",
"nudity",
"nudist",
"nudists",
"orgasm",
"orgasim",
"orgasum",
"penetration",
"breasts",
"boobs",
"b00bs",
"tit",
"tits",
"titt",
"teets",
"teez",
"vagina",
"vag1na",
"va1jina",
"vagiina",
"vaj1na",
"vajina",
"vulva",
"vullva",
"clit",
"clits",
"penis",
"pen1s",
"penas",
"penus",
"penuus",
"peenus",
"peeenusss",
"peeenus",
"peinus",
"penis-breath",
"genital",
"testicle",
"testical",
"scrotum",
"horny",
"aroused",
"climax",
"fetish",
"kinky",
"submissive",
"dominant",
"bondage",
"blow job",
"blowjob",
"boffing",
"cum",
"jism",
"jiss",
"jizm",
"jizz",
"semen",
"carpet muncher",
"lesbian",
"lezzian",
"anus",
"rectum",
"recktum",
"orifice",
"oriface",
"orifiss",
"orafis",
"enema",
"fudge packer",
"poonani",
"preteen",
"screwing",
"shemale",
"masochist",
"masokist",
"sadist",
"dominatricks",
"dominatrics",
"dominatrix",
"dyke",
"felcher",
"foreskin",
"queef",
"sphencter",
"splooge",
],
},
violence: {
name: "violence",
severity: "high",
description: "Serious violent threats and harmful actions against people",
keywords: [
"murder",
"gore",
"torture",
"terrorist",
"terrorism",
"massacre",
"slaughter",
"execute him",
"execute her",
"execution",
"assassinate",
"assassination",
"strangle",
"stab someone",
"stab you",
"stab him",
"stab her",
"kill you",
"kill him",
"kill her",
"kill myself",
"want you dead",
"want him dead",
"want her dead",
"shoot someone",
"shoot you",
"shoot him",
"shoot her",
"shoot myself",
"want to Kill",
"want to shoot",
"want to stab",
"want to strangle",
"blow up",
"blow yourself up",
"blow him up",
"blow her up",
"blow them up",
"detonate",
"detonating",
"detonation",
"explode",
"bomb someone",
"bomb you",
"bomb him",
"murder you",
"murder him",
"murder her",
"poison someone",
"poison you",
"beat you up",
"beat the shit out of",
"kick your ass",
"rape",
"sexual assault",
"domestic violence",
"child abuse",
"human trafficking",
"genocide",
"ethnic cleansing",
"war crimes",
"brutalize",
"maim",
"mutilate",
"dismember",
"decapitate",
"lynch",
"lynching",
"suffocate",
"drown someone",
"burn alive",
"set fire to",
"set fire on",
"want to burn",
"want to set fire",
"burn someone",
"burn you",
"burn him",
"burn her",
"acid attack",
"school shooting",
"mass shooting",
"bombing", // as in terrorist bombing
"suicide bombing",
"homicide",
// Violent action phrases - targeting specific people
"shooting himself",
"shooting herself",
"shooting a guy",
"shooting a girl",
"shooting a woman",
"shooting a man",
"shooting people",
"shooting someone",
"killing a guy",
"killing a girl",
"killing a woman",
"killing a man",
"killing people",
"killing someone",
"murdering him",
"murdering her",
"murdering someone",
"murdering people",
"murdering a guy",
"murdering a girl",
"murdering a woman",
"murdering a man",
"stabbing him",
"stabbing her",
"stabbing someone",
"stabbing people",
"stabbing a guy",
"stabbing a girl",
"stabbing a woman",
"stabbing a man",
"strangling him",
"strangling her",
"strangling someone",
"strangling people",
"choking him",
"choking her",
"choking someone",
"choking people",
"beating him",
"beating her",
"beating someone",
"beating people",
"attacking him",
"attacking her",
"attacking someone",
"attacking people",
"hurting him",
"hurting her",
"hurting someone",
"hurting people",
"harming him",
"harming her",
"harming someone",
"harming people",
"punching him",
"punching her",
"punching someone",
"punching people",
"kicking him",
"kicking her",
"kicking someone",
"kicking people",
"slapping him",
"slapping her",
"slapping someone",
"slapping people",
// Intent-based violent phrases - targeting people specifically
"going to kill you",
"going to kill him",
"going to kill her",
"going to kill them",
"going to shoot you",
"going to shoot him",
"going to shoot her",
"going to shoot them",
"going to stab you",
"going to stab him",
"going to stab her",
"going to stab them",
"going to murder you",
"going to murder him",
"going to murder her",
"going to murder them",
"planning to kill you",
"planning to kill him",
"planning to kill her",
"planning to kill them",
"planning to shoot you",
"planning to shoot him",
"planning to shoot her",
"planning to shoot them",
"thinking of killing you",
"thinking of killing him",
"thinking of killing her",
"thinking of killing them",
"want to eliminate you",
"want to eliminate him",
"want to eliminate her",
"want to eliminate them",
"need to kill you",
"need to kill him",
"need to kill her",
"need to kill them",
"have to kill you",
"have to kill him",
"have to kill her",
"have to kill them",
// Weapon-based violence
"gun him down",
"gun her down",
"gun someone down",
"shoot him dead",
"shoot her dead",
"shoot someone dead",
"put a bullet in",
"blow his brains out",
"blow her brains out",
"blow their brains out",
"cut his throat",
"cut her throat",
"cut someone's throat",
"slit his throat",
"slit her throat",
"slit someone's throat",
"knife someone",
"knife him",
"knife her",
// Violent death phrases
"make him disappear",
"make her disappear",
"make someone disappear",
"finish him off",
"finish her off",
"finish someone off",
"take him out",
"take her out",
"take someone out",
"get rid of him",
"get rid of her",
"get rid of someone",
"eliminate him",
"eliminate her",
"eliminate someone",
"dispose of him",
"dispose of her",
"dispose of someone",
// Mass violence phrases
"kill them all",
"shoot them all",
"murder everyone",
"eliminate everyone",
"wipe them out",
"slaughter them",
"massacre them",
"exterminate them",
"annihilate them",
// Death-related phrases with people
"dead guy",
"dead man",
"dead woman",
"dead girl",
"dead boy",
"dead person",
"dead people",
"dead body",
"dead bodies",
"corpse",
"corpses",
"corpse of",
"corpses of",
"lifeless body",
"lifeless bodies",
"killed guy",
"killed man",
"killed woman",
"killed girl",
"killed boy",
"killed person",
"killed people",
"murdered guy",
"murdered man",
"murdered woman",
"murdered girl",
"murdered boy",
"murdered person",
"murdered people",
"deceased person",
"deceased people",
"bloodied body",
"bloodied corpse",
"mangled body",
"mutilated body",
"dismembered body",
"decapitated body",
"severed head",
"severed limbs",
"chopped up body",
"body parts",
"human remains",
"rotting corpse",
"decomposing body",
"fresh corpse",
"bloody corpse",
],
},
drugs: {
name: "drugs",
severity: "medium",
description: "Illegal drugs and drug-related content",
keywords: [
"cocaine",
"heroin",
"meth",
"methamphetamine",
"marijuana",
"cannabis",
"lsd",
"ecstasy",
"molly",
"crack cocaine",
"crack",
"opium",
"morphine",
"fentanyl",
"amphetamine",
"psychedelic",
"hallucinogen",
"drug dealer",
"drug lord",
"drug trafficking",
"narcotic",
"overdose",
"addiction",
"ketamine",
"pcp",
"mdma",
"dmt",
"acid", // when referring to LSD
"crystal meth",
],
},
hate: {
name: "hate",
severity: "high",
description: "Hate speech and discriminatory content",
keywords: [
"nazi",
"nazis",
"hitler",
"holocaust",
"genocide",
"supremacist",
"racist",
"racism",
"sexist",
"homophobic",
"transphobic",
"bigot",
"discrimination",
"prejudice",
"slur",
"ethnic cleansing",
"nigger",
"nigga",
"nigur",
"niiger",
"niigr",
"n1gr",
"chink",
"g00k",
"gook",
"jap",
"japs",
"kike",
"spic",
"wetback",
"wop",
"w0p",
"daygo",
"dego",
"guiena",
"honkey",
"injun",
"kraut",
"polac",
"polack",
"polak",
"packi",
"packie",
"packy",
"paki",
"pakie",
"paky",
],
},
self_harm: {
name: "self_harm",
severity: "high",
description: "Self-harm and suicide-related content",
keywords: [
"suicide",
"self-harm",
"cut myself",
"kill myself",
"hang myself",
"off myself",
"delete myself",
"terminate myself",
"self terminate",
"end my life",
"suicidal",
"cutting myself",
"self-injury",
"overdose myself to death",
"self-destruction",
"self-mutilation",
],
},
};
/**
* Get all keywords from all categories
*/
const getAllKeywords = () => {
const allKeywords = [];
Object.values(exports.DETECTION_CATEGORIES).forEach((category) => {
allKeywords.push(...category.keywords);
});
return [...new Set(allKeywords)]; // Remove duplicates
};
exports.getAllKeywords = getAllKeywords;
/**
* Get keywords by category
*/
const getKeywordsByCategory = (categoryName) => {
return exports.DETECTION_CATEGORIES[categoryName]?.keywords || [];
};
exports.getKeywordsByCategory = getKeywordsByCategory;
/**
* Additional international and variant profanity patterns
*/
exports.ADDITIONAL_VARIANTS = [
// Leetspeak and character substitutions
"f*ck",
"sh*t",
"b*tch",
"a$$",
"@$$",
"f u c k",
"f u c k e r",
"s.o.b.",
"N*gger",
"n*gger",
"*damn",
"*dyke",
"*fuck*",
"*shit*",
"bi7ch",
"bitch*",
"cock*",
"cunt*",
"d4mn",
"dick*",
"dike*",
"fag*",
"fuk*",
"h0r",
"h4x0r",
"hoer*",
"kanker*",
"kusi*",
"kyrpa*",
"masturbat*",
"merd*",
"nigger*",
"paska*",
"pierdol*",
"pillu*",
"piss*",
"pr0n",
"queef*",
"scheiss*",
"sh!t*",
"b00b*",
"testicle*",
"titt*",
"wank*",
"wop*",
// International profanity
"amcik",
"andskota",
"ayir",
"blyat",
"cabron",
"cazzo",
"chraa",
"chuj",
"dupa",
"dziwka",
"ekrem",
"ekto",
"enculer",
"faen",
"fanculo",
"feces",
"feg",
"ficken",
"fitt",
"flikker",
"fotze",
"futkretzn",
"helvete",
"huevon",
"hui",
"kanker",
"kapiri",
"klootzak",
"knulle",
"kuk",
"kuksuger",
"kurac",
"kurwa",
"kyrpa",
"lesbo",
"mamhoon",
"mibun",
"monkleigh",
"mouliewop",
"muie",
"mulkku",
"muschi",
"nepesaurio",
"orospu",
"pajeet",
"paska",
"perse",
"picka",
"pierdol",
"pillu",
"pimmel",
"piss",
"pizda",
"poontsee",
"poop",
"pula",
"pule",
"puta",
"puto",
"qahbeh",
"rautenberg",
"schaffer",
"scheiss",
"schlampe",
"schmuck",
"screw",
"sharmuta",
"sharmute",
"shipal",
"shiz",
"skribz",
"skurwysyn",
"suka",
"vittu",
"wichser",
"yed",
"zabourah",
// Additional variants and patterns
"ass monkey",
"butt-pirate",
"flipping the bird",
"lipshits",
"lipshitz",
"nastt",
"puuke",
"puuker",
"turd",
];
/**
* Get all keywords from all categories including variants
*/
const getAllKeywordsWithVariants = () => {
const allKeywords = [];
Object.values(exports.DETECTION_CATEGORIES).forEach((category) => {
allKeywords.push(...category.keywords);
});
allKeywords.push(...exports.ADDITIONAL_VARIANTS);
return [...new Set(allKeywords)]; // Remove duplicates
};
exports.getAllKeywordsWithVariants = getAllKeywordsWithVariants;
/**
* Get categories by severity level
*/
const getCategoriesBySeverity = (severity) => {
// If severity is "none", return empty array (no categories)
if (severity === "none") {
return [];
}
return Object.entries(exports.DETECTION_CATEGORIES)
.filter(([_, category]) => category.severity === severity)
.map(([name]) => name);
};
exports.getCategoriesBySeverity = getCategoriesBySeverity;
/**
* Get categories up to a maximum severity level (inclusive)
*/
const getCategoriesUpToSeverity = (maxSeverity) => {
// If maxSeverity is "none", return empty array (no categories allowed)
if (maxSeverity === "none") {
return [];
}
const severityOrder = { low: 1, medium: 2, high: 3 };
const maxLevel = severityOrder[maxSeverity];
return Object.entries(exports.DETECTION_CATEGORIES)
.filter(([_, category]) => severityOrder[category.severity] <= maxLevel)
.map(([name]) => name);
};
exports.getCategoriesUpToSeverity = getCategoriesUpToSeverity;
/**
* Get all keywords for categories with specific severity levels
*/
const getKeywordsBySeverityLevels = (severityLevels) => {
// If "none" is included, return empty array (no keywords allowed)
if (severityLevels.includes("none")) {
return [];
}
const keywords = [];
Object.values(exports.DETECTION_CATEGORIES).forEach((category) => {
if (severityLevels.includes(category.severity)) {
keywords.push(...category.keywords);
}
});
return [...new Set(keywords)]; // Remove duplicates
};
exports.getKeywordsBySeverityLevels = getKeywordsBySeverityLevels;
/**
* Get all category names
*/
const getCategoryNames = () => {
return Object.keys(exports.DETECTION_CATEGORIES);
};
exports.getCategoryNames = getCategoryNames;
//# sourceMappingURL=wordLists.js.map