Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bad-words

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bad-words - npm Package Compare versions

Comparing version 0.0.3 to 0.5.0

test/addWords.js

58

lib/badwords.js

@@ -1,34 +0,40 @@

var detector = (function(){
function Filter(){
this.list = require('./lang.json').words;
}
var detector = (function() {
function Filter(options) {
options = options || {};
this.list = require('./lang.json').words;
this.placeHolder = options.placeHolder || '*';
this.Factory = Filter;
}
Filter.prototype.isProfane = function isProfane(string){
for(var i = 0; i < this.list.length; i++)
if(string.toLowerCase() == this.list[i].toLowerCase())
return true;
Filter.prototype.isProfane = function isProfane(string) {
for (var i = 0; i < this.list.length; i++) {
var words = string.split(' ');
for (var j = 0; j < words.length; j++) {
if (words[j].toLowerCase().replace(/\*|\+|\-|\./g, '') === this.list[i].toLowerCase()) {
return true;
}
}
}
return false;
};
return false;
};
Filter.prototype.replaceWord = function replaceWord(string) {
return string.replace(/\*|\+|\-|\./g, '').replace(/\w/g, this.placeHolder);
};
Filter.prototype.replaceWord = function replaceWord(string){
return string.split("").map(function(c){
return "*";
}).join("");
};
Filter.prototype.clean = function clean(string) {
return string.split(' ').map(function(word) {
return this.isProfane(word) ? this.replaceWord(word) : word;
}.bind(this)).join(' ');
};
Filter.prototype.clean = function clean(string){
return string.split(" ").map(function(word){
return this.isProfane(word) ? this.replaceWord(word) : word;
}.bind(this)).join(" ");
};
return Filter;
Filter.prototype.addWords = function addWords(words) {
words = (words instanceof Array) ? words : [words];
this.list = this.list.concat(words);
};
return Filter;
})();
String.prototype.clean = function clean(){
var filter = new detector();
return filter.clean(this);
};
String.prototype.clean = String.prototype.clean || function(){};
module.exports = new detector();
{
"name": "bad-words",
"version": "0.0.3",
"version": "0.5.0",
"description": "A javascript filter for bad words",

@@ -5,0 +5,0 @@ "main": "./lib/badwords",

@@ -1,2 +0,2 @@

badwords
badwords v0.5.0
========

@@ -6,7 +6,7 @@

```javascript
```
npm install bad-words
```
#Examples
```javascript
```
var filter = require('bad-words');

@@ -16,17 +16,38 @@

```
Outputs:
#####Outputs:
```
Don't be an ******
```
#String Helper
###Factory
Allows the creation of new instances of a filter
```javascript
require('bad-words');
```
var filter = require('bad-words');
var customFilter = new filter.Factory();
console.log("Don't be an ash0le".clean());
customFilter.clean('Bad words...');
```
Outputs:
Don't be an ******
###Placeholder Overrides
```
var filter = require('bad-words');
var customFilter = new filter.Factory({ placeHolder: 'x'});
customFilter.clean('Don't be an ash0le');
```
#####Outputs:
```
Don't be an xxxxxx
```
#String Helper
Will no longer be supported and removed in the next release.
#Testing
```
mocha
```
========

@@ -33,0 +54,0 @@

@@ -7,14 +7,20 @@ require('assert');

describe('clean',function(){
it("Should replace a bad word within a sentence asterisks (******)",function(){
assert(filter.clean("Don't be an ash0le") == "Don't be an ******");
it('Should replace a bad word within a sentence asterisks (******)',function(){
assert(filter.clean('Don\'t be an ash0le') === 'Don\'t be an ******');
});
it("Should replace multiple instances of any bad words within a sentence asterisks (******)",function(){
assert(filter.clean("cnts ash0le knob xxx") == "**** ****** **** ***");
it('Should replace multiple instances of any bad words within a sentence asterisks (******)',function(){
assert(filter.clean('cnts ash0le knob xxx') === '**** ****** **** ***');
});
it("Should not replace anything within a sentence if there are no bad words",function(){
assert(filter.clean("The cat ran fast") == "The cat ran fast");
it('Should not replace anything within a sentence if there are no bad words',function(){
assert(filter.clean('The cat ran fast') === 'The cat ran fast');
});
it('Should replace a string with proper placeholder when overridden', function(){
var customFilter = new filter.Factory({ placeHolder:'x'});
assert(customFilter.clean('This is a hells good test') === 'This is a xxxxx good test');
});
});
});

@@ -15,3 +15,7 @@ require('assert');

});
it("Should be able to detect a bad word in a sentence",function(){
assert(filter.isProfane("that person is an ash0le"));
})
});
});
});
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