@2toad/profanity
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -15,3 +15,3 @@ "use strict"; | ||
const file = fs_1.readFileSync(filename, "utf8"); | ||
this.words = file.split("\n").filter((x) => x); | ||
this.words = file.split(/[\r\n]+/).filter((x) => x); | ||
this.onListChanged(); | ||
@@ -18,0 +18,0 @@ } |
@@ -7,2 +7,5 @@ "use strict"; | ||
const list_1 = require("./list"); | ||
function escapeRegExp(text) { | ||
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
} | ||
class Profanity { | ||
@@ -29,4 +32,6 @@ constructor(options) { | ||
buildRegex() { | ||
const blacklistPattern = `${this.options.wholeWord ? "\\b" : ""}(${this.blacklist.words.join("|")})${this.options.wholeWord ? "\\b" : ""}`; | ||
const whitelistPattern = this.whitelist.empty ? "" : `(?!${this.whitelist.words.join("|")})`; | ||
const escapedBlacklistWords = this.blacklist.words.map(escapeRegExp); | ||
const escapedWhitelistWords = this.whitelist.words.map(escapeRegExp); | ||
const blacklistPattern = `${this.options.wholeWord ? "\\b" : ""}(${escapedBlacklistWords.join("|")})${this.options.wholeWord ? "\\b" : ""}`; | ||
const whitelistPattern = this.whitelist.empty ? "" : `(?!${escapedWhitelistWords.join("|")})`; | ||
this.regex = new RegExp(whitelistPattern + blacklistPattern, "ig"); | ||
@@ -33,0 +38,0 @@ } |
@@ -47,2 +47,11 @@ "use strict"; | ||
}); | ||
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); | ||
}); | ||
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); | ||
}); | ||
it("Should return true when some regex characters are present as profanity", () => { | ||
chai_1.expect(customProfanity.exists("lovea$$")).to.equal(true); | ||
}); | ||
}); | ||
@@ -49,0 +58,0 @@ describe("censor", () => { |
@@ -21,2 +21,4 @@ 4r5e | ||
a$$ | ||
as$ | ||
a$s | ||
b!tch | ||
@@ -23,0 +25,0 @@ b00bs |
{ | ||
"name": "@2toad/profanity", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A JavaScript profanity filter", | ||
@@ -42,3 +42,2 @@ "homepage": "https://github.com/2Toad/Profanity", | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -51,3 +50,3 @@ "@types/chai": "^4.2.14", | ||
"chai": "^4.2.0", | ||
"eslint": "^7.15.0", | ||
"eslint": "7.15.0", | ||
"husky": "^4.3.6", | ||
@@ -54,0 +53,0 @@ "lint-staged": "^10.5.3", |
# Profanity | ||
[![GitHub version](https://badge.fury.io/gh/2Toad%2FProfanity.svg)](https://badge.fury.io/gh/2Toad%2FProfanity) | ||
[![GitHub version](https://badge.fury.io/gh/2Toad%2FProfanity.svg)](https://github.com/2Toad/Profanity/releases) | ||
[![Downloads](https://img.shields.io/npm/dm/@2toad/profanity.svg)](https://www.npmjs.com/package/@2toad/profanity) | ||
[![Build Status](https://travis-ci.org/2Toad/Profanity.svg?branch=master)](https://travis-ci.org/2Toad/Profanity) | ||
[![Build status](https://github.com/2toad/profanity/actions/workflows/build.yml/badge.svg)](https://github.com/2Toad/Profanity/actions/workflows/build.yml) | ||
@@ -7,0 +7,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
43366
34
468