Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
no-profanity
Advanced tools
A JavaScript package to detect and filter profanity. Yes this code, and with code I mean tests, contain profanity. But what do you expect from a test in a no-profanity package.
npm i no-profanity
Thanks to bad-words for the original package. This package is a rewrite of that package, with some extra features and a lot of performance improvements.
Using the no-profanity package is very simple. You can use it to detect profanity, or to filter profanity from a string. There are some basic options as well, such as overriding the placeholder character, or adding/removing words from the filterlist.
A basic sample showing a simple checker
import { isProfane } from 'no-profanity';
console.log(isProfane("Don't be an asshole")); // true
console.log(isProfane("This is a nice text")); // false
A basic sample showing how to replace profanities
import { replaceProfanities } from 'no-profanity';
console.log(replaceProfanities("Don't be an asshole")); // Don't be an *******
console.log(replaceProfanities("This is a nice text")); // This is a nice text
A basic sample returning the profanities
console.log(containsProfanities("what an asshole"));
Will return:
[ {
word: 'asshole',
index: 8
} ]
There are some overrides possible, but as soon as you want to use an override you will no longer be able pass a string to the functions defined above, but instead, they require an arguments object, like this:
replaceProfanities({
testString: "testable string",
options: {}
});
The options object should contain a property called replacement
which should be a string of length 1, unless you want a longer replacement value as the original wordlength. The default value is *
.
replaceProfanities({
testString: "testable string",
options: {
replacement: '#'
}
});
The options object should contain a property called excludes
which should be an array of strings you don't want to filter on.
replaceProfanities({
testString: "testable string",
options: {
excludes: ['testable']
}
});
You can also remove all words from the filter list so you can start your own, using the emptyList
property.
replaceProfanities({
testString: "testable string",
options: {
emptyList: true
}
});
The options object should contain a property called includes
which should be an array of strings you want to filter on.
replaceProfanities({
testString: "testable string",
options: {
includes: ['testable']
}
});
The options object has the option to contain a regex pattern to sanitize the string before checking for profanities.
replaceProfanities({
testString: "testable string",
options: {
preSanitize: /[^a-zA-Z0-9]/g
}
});
All matches will be replaced with an empty string. If you want to change the replacement for preSanitize
, you can use the preSanitizeReplacement
property.
replaceProfanities({
testString: "tabs are the best",
options: {
preSanitizeReplacement: "spaces",
preSanitize: /\btabs\b/,
}
});
This package is the replacement for the bad-words
package which is outdated and slow. According to a handful of benchmarks, this package is about 150 times as fast.
See also this page for more information and the migration guide.
Most options from the bad-words
package are usable in the options
object to be used in this package. However, the replaceRegex
option is not supported.
Any contributions are highly appreciated. If you want to contribute, please fork the repository and create a pull request. If you have any questions, feel free to create an issue.
This project is licensed under the MIT License - see the LICENSE file for details. With MIT comes the freedom to use the code for whatever you want, but a credit would be appreciated.
FAQs
A JavaScript package to detect and filter profanity
The npm package no-profanity receives a total of 6,175 weekly downloads. As such, no-profanity popularity was classified as popular.
We found that no-profanity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.