New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@2toad/profanity

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@2toad/profanity - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

.eslintcache

0

dist/index.d.ts
export * from "./profanity";
export * from "./profanity-options";
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

1

dist/list.d.ts

@@ -6,5 +6,4 @@ export declare class List {

constructor(onListChanged: () => void);
loadFile(filename: string): void;
removeWords(words: string[]): void;
addWords(words: string[]): void;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.List = void 0;
const fs_1 = require("fs");
class List {

@@ -13,7 +12,2 @@ constructor(onListChanged) {

}
loadFile(filename) {
const file = fs_1.readFileSync(filename, "utf8");
this.words = file.split(/[\r\n]+/).filter((x) => x);
this.onListChanged();
}
removeWords(words) {

@@ -20,0 +14,0 @@ this.words = this.words.filter((x) => !words.includes(x));

@@ -0,0 +0,0 @@ export declare class ProfanityOptions {

@@ -0,0 +0,0 @@ "use strict";

@@ -0,0 +0,0 @@ import { ProfanityOptions } from "./profanity-options";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.profanity = exports.Profanity = void 0;
const path_1 = require("path");
const profanity_options_1 = require("./profanity-options");
const list_1 = require("./list");
function escapeRegExp(text) {
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
const misc_1 = require("./utils/misc");
const profane_words_1 = require("./data/profane-words");
class Profanity {

@@ -15,3 +13,3 @@ constructor(options) {

this.blacklist = new list_1.List(() => this.buildRegex());
this.blacklist.loadFile(path_1.resolve(__dirname, "words.txt"));
this.blacklist.addWords(profane_words_1.default);
}

@@ -32,4 +30,4 @@ exists(text) {

buildRegex() {
const escapedBlacklistWords = this.blacklist.words.map(escapeRegExp);
const escapedWhitelistWords = this.whitelist.words.map(escapeRegExp);
const escapedBlacklistWords = this.blacklist.words.map(misc_1.escapeRegExp);
const escapedWhitelistWords = this.whitelist.words.map(misc_1.escapeRegExp);
const blacklistPattern = `${this.options.wholeWord ? "\\b" : ""}(${escapedBlacklistWords.join("|")})${this.options.wholeWord ? "\\b" : ""}`;

@@ -36,0 +34,0 @@ const whitelistPattern = this.whitelist.empty ? "" : `(?!${escapedWhitelistWords.join("|")})`;

@@ -8,12 +8,12 @@ "use strict";

it("should return true when profanity exists in a sentence", () => {
chai_1.expect(_1.profanity.exists("I like big butts and I cannot lie")).to.equal(true);
(0, chai_1.expect)(_1.profanity.exists("I like big butts and I cannot lie")).to.equal(true);
});
it("should return true when profanity exists as a single word", () => {
chai_1.expect(_1.profanity.exists("butt")).to.equal(true);
(0, chai_1.expect)(_1.profanity.exists("butt")).to.equal(true);
});
it("should return false when profanity is not a whole word in a sentence", () => {
chai_1.expect(_1.profanity.exists("Should we censor the word arsenic?")).to.equal(false);
(0, chai_1.expect)(_1.profanity.exists("Should we censor the word arsenic?")).to.equal(false);
});
it("should return true when profanity exists within multiple lines", () => {
chai_1.expect(_1.profanity.exists(`
(0, chai_1.expect)(_1.profanity.exists(`
Nothing profane on line 1.

@@ -25,3 +25,3 @@ Censoring butt on line 2.

it("should return false when profanity does not exist", () => {
chai_1.expect(_1.profanity.exists("I like big glutes and I cannot lie")).to.equal(false);
(0, chai_1.expect)(_1.profanity.exists("I like big glutes and I cannot lie")).to.equal(false);
});

@@ -34,6 +34,6 @@ });

it("should return true when profanity is part of a word in a sentence", () => {
chai_1.expect(customProfanity.exists("Should we censor the word arsenic?")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word arsenic?")).to.equal(true);
});
it("should return true when profanity is part of a word, within multiple lines", () => {
chai_1.expect(customProfanity.exists(`
(0, chai_1.expect)(customProfanity.exists(`
Nothing profane on line 1.

@@ -45,15 +45,15 @@ Censoring arsenic on line 2.

it("should return false when profanity does not exist", () => {
chai_1.expect(customProfanity.exists("I like big glutes and I cannot lie")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("I like big glutes and I cannot lie")).to.equal(false);
});
it("should return true when profanity exists as part of a single word", () => {
chai_1.expect(customProfanity.exists("arsenic")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("arsenic")).to.equal(true);
});
it("Should return false when the last character is an 'A' with no profanity (A$$ edge case)", () => {
chai_1.expect(customProfanity.exists("FUNTIMESA")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("FUNTIMESA")).to.equal(false);
});
it("Should return true when the last character is an 'A' and there is profanity (A$$ edge case)", () => {
chai_1.expect(customProfanity.exists("BUTTSA")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("BUTTSA")).to.equal(true);
});
it("Should return true when some regex characters are present as profanity", () => {
chai_1.expect(customProfanity.exists("lovea$$")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("lovea$$")).to.equal(true);
});

@@ -64,7 +64,7 @@ });

const censored = _1.profanity.censor("I like big butts and I cannot lie");
chai_1.expect(censored.includes(_1.profanity.options.grawlix)).to.equal(true);
(0, chai_1.expect)(censored.includes(_1.profanity.options.grawlix)).to.equal(true);
});
it("should remove profanity from a sentence", () => {
const censored = _1.profanity.censor("I like big butts (aka arses) and I cannot lie");
chai_1.expect(_1.profanity.exists(censored)).to.equal(false);
(0, chai_1.expect)(_1.profanity.exists(censored)).to.equal(false);
});

@@ -77,3 +77,3 @@ it("should remove profanity from multiple lines", () => {

`);
chai_1.expect(_1.profanity.exists(censored)).to.equal(false);
(0, chai_1.expect)(_1.profanity.exists(censored)).to.equal(false);
});

@@ -83,7 +83,7 @@ it("should not alter sentence without profanity", () => {

const censored = _1.profanity.censor(original);
chai_1.expect(censored).to.equal(original);
(0, chai_1.expect)(censored).to.equal(original);
});
it("should remove profanity when profanity exists as a single word", () => {
const censored = _1.profanity.censor("butt");
chai_1.expect(_1.profanity.exists(censored)).to.equal(false);
(0, chai_1.expect)(_1.profanity.exists(censored)).to.equal(false);
});

@@ -95,3 +95,3 @@ });

customProfanity.addWords(["aardvark"]);
chai_1.expect(customProfanity.exists("Should we censor the word aardvark?")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word aardvark?")).to.equal(true);
});

@@ -101,3 +101,3 @@ it("should add mulitple words to the list of profane words", () => {

customProfanity.addWords(["aardvark", "zebra"]);
chai_1.expect(customProfanity.exists("Should we censor the word aardvark and zebra?")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word aardvark and zebra?")).to.equal(true);
});

@@ -109,3 +109,3 @@ });

customProfanity.removeWords(["butts"]);
chai_1.expect(customProfanity.exists("I like big butts and I cannot lie")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("I like big butts and I cannot lie")).to.equal(false);
});

@@ -115,3 +115,3 @@ it("should remove mulitple words from the list of profane words", () => {

customProfanity.removeWords(["butts", "arses"]);
chai_1.expect(customProfanity.exists("I like big butts (aka arses) and I cannot lie")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("I like big butts (aka arses) and I cannot lie")).to.equal(false);
});

@@ -123,3 +123,3 @@ });

customProfanity.whitelist.addWords(["butt"]);
chai_1.expect(customProfanity.exists("Should we censor the word butt?")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word butt?")).to.equal(false);
});

@@ -129,3 +129,3 @@ it("should whitelist multiple words", () => {

customProfanity.whitelist.addWords(["butt", "arse"]);
chai_1.expect(customProfanity.exists("Should we censor the word butt or arse?")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word butt or arse?")).to.equal(false);
});

@@ -139,3 +139,3 @@ });

customProfanity.whitelist.addWords(["buttocks"]);
chai_1.expect(customProfanity.exists("Should we censor the word buttocks?")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word buttocks?")).to.equal(false);
});

@@ -145,3 +145,3 @@ it("should whitelist multiple words", () => {

customProfanity.whitelist.addWords(["buttocks", "arsenic"]);
chai_1.expect(customProfanity.exists("Should we censor the word buttocks or arsenic?")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("Should we censor the word buttocks or arsenic?")).to.equal(false);
});

@@ -153,5 +153,5 @@ });

customProfanity.whitelist.addWords(["butts", "arses"]);
chai_1.expect(customProfanity.exists("I like big butts and I cannot lie")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("I like big butts and I cannot lie")).to.equal(false);
customProfanity.whitelist.removeWords(["butts"]);
chai_1.expect(customProfanity.exists("I like big butts and I cannot lie")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("I like big butts and I cannot lie")).to.equal(true);
});

@@ -161,5 +161,5 @@ it("should remove multiple words from the whitelist", () => {

customProfanity.whitelist.addWords(["butts", "arses"]);
chai_1.expect(customProfanity.exists("I like big butts (aka arses) and I cannot lie")).to.equal(false);
(0, chai_1.expect)(customProfanity.exists("I like big butts (aka arses) and I cannot lie")).to.equal(false);
customProfanity.whitelist.removeWords(["butts"]);
chai_1.expect(customProfanity.exists("I like big butts (aka arses) and I cannot lie")).to.equal(true);
(0, chai_1.expect)(customProfanity.exists("I like big butts (aka arses) and I cannot lie")).to.equal(true);
});

@@ -166,0 +166,0 @@ });

{
"name": "@2toad/profanity",
"version": "1.3.1",
"version": "1.4.0",
"description": "A JavaScript profanity filter",

@@ -14,9 +14,11 @@ "homepage": "https://github.com/2Toad/Profanity",

"scripts": {
"dev": "tsc -w",
"lint": "npx eslint src",
"local": "npx tsc --watch",
"lint": "npx eslint src --cache",
"lint:fix": "npx eslint src --cache --fix",
"prettier": "npx prettier --write .",
"test": "mocha -r ts-node/register src/**/*.spec.ts",
"prepare": "npm run build",
"build": "npm run lint && npm run test && tsc && cp src/words.txt dist",
"deploy": "npm publish"
"clean": "npx rimraf dist",
"build": "npm run clean && npx tsc",
"deploy": "npm publish",
"prepublishOnly": "npm run lint && npm run test && npm run build"
},

@@ -44,21 +46,16 @@ "repository": {

"devDependencies": {
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.14",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"chai": "^4.2.0",
"eslint": "7.15.0",
"husky": "^4.3.6",
"lint-staged": "^10.5.3",
"mocha": "^8.2.1",
"prettier": "2.2.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node": "^17.0.31",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"chai": "^4.3.6",
"eslint": "^7.32.0",
"lint-staged": "^12.4.1",
"mocha": "^9.2.2",
"prettier": "2.6.2",
"rimraf": "^3.0.2",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {

@@ -65,0 +62,0 @@ "*.ts": [

@@ -5,3 +5,3 @@ # Profanity

[![Downloads](https://img.shields.io/npm/dm/@2toad/profanity.svg)](https://www.npmjs.com/package/@2toad/profanity)
[![Build status](https://github.com/2toad/profanity/actions/workflows/build.yml/badge.svg)](https://github.com/2Toad/Profanity/actions/workflows/build.yml)
[![Build status](https://github.com/2toad/profanity/actions/workflows/nodejs.yml/badge.svg)](https://github.com/2Toad/Profanity/actions/workflows/nodejs.yml)

@@ -8,0 +8,0 @@ A JavaScript profanity filter (with TypeScript support)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc