![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Robust, extensible profanity filter for NodeJS.
f...u c k
, fuuuuuuuckkk
, ʃṳ𝒸𝗄
, wordsbeforefuckandafter
and so on. There's no need to manually write out all the variants either: just adding the pattern fuck
will match all of the cases above by default.$ npm install obscenity
$ yarn add obscenity
$ pnpm add obscenity
First, import Obscenity:
const {
RegExpMatcher,
TextCensor,
englishDataset,
englishRecommendedTransformers,
} = require('obscenity');
Or, in TypeScript/ESM:
import {
RegExpMatcher,
TextCensor,
englishDataset,
englishRecommendedTransformers,
} from 'obscenity';
Now, we can create a new matcher using the English preset.
const matcher = new RegExpMatcher({
...englishDataset.build(),
...englishRecommendedTransformers,
});
Now, we can use our matcher to search for profanities in the text. Here's two examples of what you can do:
Check if there are any matches in some text:
if (matcher.hasMatch('f.uck you')) {
console.log('The input text contains profanities.');
}
// The input text contains profanities.
Output the positions of all matches along with the original word used:
// Pass "true" as the "sorted" parameter so the matches are sorted by their position.
const matches = matcher.getAllMatches('ʃ𝐟ʃὗƈk ỹоứ 𝔟!!!ⁱẗ𝙘ɦ', true);
for (const match of matches) {
const { phraseMetadata, startIndex, endIndex } =
englishDataset.getPayloadWithPhraseMetadata(match);
console.log(
`Match for word ${phraseMetadata.originalWord} found between ${startIndex} and ${endIndex}.`,
);
}
// Match for word fuck found between 0 and 6.
// Match for word bitch found between 12 and 21.
Censoring matched text:
To censor text, we'll need to import another class: the TextCensor
.
Some other imports and creation of the matcher have been elided for simplicity.
const { TextCensor, ... } = require('obscenity');
// ...
const censor = new TextCensor();
const input = 'fuck you little bitch';
const matches = matcher.getAllMatches(input);
console.log(censor.applyTo(input, matches));
// %@$% you little **%@%
This is just a small slice of what Obscenity can do: for more, check out the documentation.
Note: As with all swear filters, Obscenity is not perfect (nor will it ever be). Use its output as a heuristic, and not as the sole judge of whether some content is appropriate or not.
With the English preset, Obscenity (correctly) finds matches in all of the following texts:
...and it does not match on the following:
For a step-by-step guide on how to use Obscenity, check out the guide.
Otherwise, refer to the auto-generated API documentation.
Issues can be reported using the issue tracker. If you'd like to submit a pull request, please read the contribution guide first.
Obscenity © Joe L. under the MIT license. Authored and maintained by Joe L.
GitHub @jo3-l
0.1.1, 0.1.2, 0.1.3
Versions skipped due to temporary issue with release workflow.
FAQs
Robust, extensible profanity filter.
We found that obscenity demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.