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

no-swears

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

no-swears - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

swearList.js

76

index.js

@@ -9,6 +9,5 @@ /**

"use strict";
'use strict';
const fs = require("fs");
const path = require("path");
const swearList = require('./swearList');

@@ -19,12 +18,18 @@ module.exports = {

**/
filter: (words, callback) => {
var finalString = words;
swearList(lines => {
for (var i = 0; i < lines.length; i++) {
var bw = new RegExp(lines[i], "gi");
finalString = finalString.replace(bw, "*".repeat(lines[i].length));
}
callback(finalString);
filterSwearWords: (words, callback) => {
let finalString = words;
swearList.getList((lines) => {
callback(getFilteredString(finalString, lines));
});
},
filterSync: (words) => {
var lines = swearListSync()
var finalString = words;
for (var i = 0; i < lines.length; i++) {
var bw = new RegExp(lines[i], "gi");
finalString = finalString.replace(bw, "*".repeat(lines[i].length));
}
return finalString;
},
/**

@@ -34,35 +39,32 @@ * True if swearword is found, false if not

hasSwears: (words, callback) => {
swearList(lines => {
var b = false;
for (var i = 0; i < lines.length; i++) {
if (words.indexOf(lines[i]) > -1) {
b = true;
}
}
callback(b);
swearList.getList((lines) => {
callback(hasSwearWords(words, lines));
});
},
hasSwearsSync: (words) => {
var lines = swearListSync()
var b = false
for (var i = 0; i < lines.length; i++) {
if (words.indexOf(lines[i]) > -1) {
b = true;
}
let lines = swearList.getListSync();
return hasSwearWords(words, lines);
}
};
let hasSwearWords = (words, lines) => {
let itHasASwear = false;
for (let i = 0; i < lines.length; i++) {
if (words.indexOf(lines[i]) > -1) {
itHasASwear = true;
}
return b
}
return itHasASwear;
};
var swearList = callback => {
fs.readFile(path.join(__dirname, "swearwords.txt"), "utf8", (err, data) => {
if (err) throw err;
data = data.replace(new RegExp("\r", "g"), "").split("\n");
callback(data);
});
let getFilteredString = (finalString, lines) => {
for (let i = 0; i < lines.length; i++) {
let badWord = new RegExp(lines[i], 'gi');
finalString = finalString.replace(badWord, '*'.repeat(lines[i].length));
}
return finalString;
};
var swearListSync = () => {
var data = fs.readFileSync(path.join(__dirname, "swearwords.txt"), "utf8")
data = data.replace(new RegExp("\r", "g"), "").split("\n");
return data
}
{
"name": "no-swears",
"version": "1.2.1",
"version": "1.3.0",
"description": "Filter swearwords out of your strings automagically",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -23,3 +23,3 @@ no-swears

### filter(string, callback)
### filterSwearWords(string, callback)

@@ -32,3 +32,3 @@ This is the most basic filtering function, and requires the offending

noswears.filter(badString, goodString => {
noswears.filterSwearWords(badString, goodString => {
console.log(goodString) // "this is a ****ing string"

@@ -35,0 +35,0 @@ })

@@ -42,2 +42,4 @@ anal

God damn
hecc
heck
hell

@@ -78,2 +80,2 @@ homo

whore
wtf
wtf

@@ -1,36 +0,57 @@

"use strict";
'use strict';
const noswears = require("./index");
const noswears = require('./index');
const expected = "**** brain**** is a weird *****";
let badString = "hell brainfuck is a weird bitch";
noswears.filterSwearWords(badString, goodString => {
let expected = '**** brain**** is a weird *****';
noswears.filter(badString, goodString => {
var expected = "**** brain**** is a weird *****";
console.log(
'Testing filter\nWant string "' + expected + '", got',
goodString
`Testing filterSwearWords
Want string "${expected}", got "${goodString}"`
);
if (goodString == expected) {
console.log("✔ Success!\n");
if (goodString === expected) {
console.log('✔ Success!');
} else {
console.log("✖ Failed!\n");
console.log('✖ Failed!');
}
});
var filterSyncResult = noswears.filterSync(badString)
console.log(
'Testing filter\nWant string "' + expected + '", got',
expected
);
if (filterSyncResult === expected) {
console.log("✔ Success!\n");
} else {
console.log("✖ Failed!\n");
}
noswears.hasSwears(badString, swearBool => {
console.log("Testing hasSwears\nWant true, got", swearBool);
if (swearBool == true) {
console.log("✔ Success!\n");
console.log(
`Testing hasSwears
Want true, got ${swearBool}`
);
if (swearBool === true) {
console.log('✔ Success!');
} else {
console.log("✖ Failed!\n");
console.log('✖ Failed!');
}
});
let hasSwearsSyncResult = noswears.hasSwearsSync(badString);
var hasSwearsSyncResult = noswears.hasSwearsSync(badString)
console.log("\nTesting hasSwearsSync\nWant true, got", hasSwearsSyncResult)
console.log(
`Testing hasSwearsSync
Want true, got ${hasSwearsSyncResult}`
);
if (hasSwearsSyncResult) {
console.log("✔ Success!\n");
console.log('✔ Success!');
} else {
console.log("✖ Failed!\n");
console.log('✖ Failed!');
}
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