npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongoose-profanity

v0.2.1

Published

> A plugin to auto-moderate profanity in your content.

Downloads

37

Readme

Mongoose Profanity Plugin

A plugin to auto-moderate profanity in your content.

This plugin will add a pre-save hook to your model to run a profanity check in your content, perform a chosen behaviour (Obscuring forbidden words by default), add flags to your entry and turning a blackListed field to true when the length of the field flags on your entry reaches a limit.

With default options it will obscure forbidden words in the following format: 'a*****b'.

In replace mode it will replace forbidden words with random inoffensive replacement words on save.

The plugin adds the following fields to your schema:

To find out more about the list of swearwords check to module used by this plugin: profanity-util

Moved to mongoose 4.x since version 0.2.0, for mongoose 3.x please use version 0.1.6

Install

To install, run:

npm install mongoose-profanity

Simple usage

Setup a 'self-moderating' model:

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    profanityPlugin = require('mongoose-profanity');

var TestSchema = new Schema({
    message: String
});

TestSchema.plugin(profanityPlugin);

var Test = mongoose.model('Test', TestSchema);

var test = new Test({
    message: 'What a bloody damn horrible weather, crap!'
}).save(function (err, entry) {
    console.log(entry.message, entry.flags, entry.blackListed);
    // 'What a b****y d**n horrible day, c**p!', [ .. ], true
});

Only query entries which have not been blacklisted:

Test.find({ blackListed: false }, function (err, entries) {
	console.log(entries.length);
	// 0
})

Advanced examples

// Obscure a custom list of forbidden words with a given symbol, blacklist if 1 more are found

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    profanityPlugin = require('mongoose-profanity');

var TestSchema = new Schema({
    message: String,
    uncheckedMessage: String
});

TestSchema.plugin(profanityPlugin, {
    maxFlags: 1,
    forbiddenList: [ 'politics', 'business' ],
    obscureSymbol: '%',
    fields: [ 'message' ]
});

var Test = mongoose.model('Test', TestSchema);

var test = new Test({
    message: 'We are not allowed to talk politics or business',
    uncheckedMessage: 'We can totally talk business here'
}).save(function (err, entry) {
    console.log(entry.message, entry.flags, entry.blackListed);
    // 'We are not allowed to talk p%%%%%%s or b%%%%%%s', [ .. ], true

	console.log(uncheckedMessage);
	// We can totally talk business here
});

Advanced examples

// Replace a custom list of forbidden words with a custom list of replacement words, never blacklist

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    profanityPlugin = require('mongoose-profanity');

var TestSchema = new Schema({
    message: String
});

TestSchema.plugin(profanityPlugin, {
    maxFlags: 0,
    forbiddenList: [ 'google', 'bing' ],
    replacementsList: [ 'some search engine' ],
    fields: [ 'message' ]
});

var Test = mongoose.model('Test', TestSchema);

var test = new Test({
    message: "I'd rather use Google instead of Bing"
}).save(function (err, entry) {
    console.log(entry.message, entry.flags, entry.blackListed);
    // 'I'd rather use some search engine instead than some search engine', [ .. ], true
});

Plugin options

  • fields - Array of schema fields to be checked by the plugin
  • forbiddenList - Array of forbidden terms to replace or obscure
  • replacementsList - Array of replacement words (To pick randomly from)
  • maxFlags - Max flags before blacklisting (Prevents addition of custom fields, flagging and blacklisting if falsy)
  • replace- If set to true it will replace forbidden words with innocuous replacement words
  • obscureSymbol - Symbol used to obscure words if obscured is set to true

Added schema fields

  • flags: FlagSchema - Flag object used by the library, open to different uses for integration (See Flag Schema)
  • blackListed: Boolean - Turns to true when the length of flags is greater than configured limit (3 by default)

Flag Schema

The flag schema can be used for different purposes, in order to make the best out of the blacklist feature in your application.

The fields in the schema are the following:

  • author: Mixed object, type and content left to the discretion of the user
  • reason: String containing reason for the flagging. (E.g. 'Inappropriate language')

Test

Run unit-tests with npm test. Make sure a local mongo server is running in order for the tests to run.

Contribute

All contributions are welcome as long as tests are written.

Licence

Copyright (C) 2014, 2017 Kano Computing Ltd. Released under the MIT licence.