FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

swearjar

v1.4.1 Public

cfmlbadges cfmlbadges cfmlbadges cfmlbadges cfmlbadges cfmlbadges cfmlbadges cfmlbadges cfmlbadges

swearjar

Profanity detection and filtering library for CFML applications

Installation

This component can be installed as standalone or as a ColdBox Module. Either approach requires a simple CommandBox command:

box install swearjar

ColdBox Module

This package is also a ColdBox module. The module can be configured by creating a swearjar configuration structure in your application configuration file (config/Coldbox.cfc) with the following settings:

swearjar = {
     libraryFilePath = '' // The path to your chosen profanity library JSON file
};

You can optionally leave this configuration out and swearjar will use the default en_US.json file.

Then you can inject the CFC via Wirebox:

property name="swearjar" inject="[email protected]";

Usage

Instantiate the component:

swearJar = new swearjar();

swearjar.profane(text)

Returns true if the given string contains profanity.

swearJar.profane( 'hello there' ); // false
swearJar.profane( 'hello mother f-bomb' ); // true

swearjar.censor(text)

Replaces profanity with asterisks.

var clean = swearjar.censor( 'f-bomb you' ); // **** you

swearjar.sugarcoat(text)

Replaces profanity with a replacement word, if one exists within the library file. If not, the word will be replaced with asterisks.

var clean = swearjar.sugarcoat( 'Your life is like poor pornography' ); // Your life is like poor erotic literature

swearjar.unicorn(text)

Replaces profanity with the word unicorn.

var clean = swearjar.unicorn( 'fuck you, you fucking stupid cunt!' ); // unicorn you, you unicorn stupid unicorn!

swearjar.words(text)

Get the words alongside their categories.

swearjar.words( 'fuck you john doe' ); // { fuck: ['sexual'] }

swearjar.detailedProfane(text)

Get the words alongside their categories, count and a censored version of the text.

swearjar.detailedProfane( 'fuck you john doe' );

returns:

{
  categoryCount: {
    sexual: 1
  },
  censored: '**** you john doe',
  profane: true,
  wordCount: {
    fuck: 1
  },
  words: {
    fuck: [
      'sexual'
    ]
  }
}

swearjar.scorecard(text)

Generates a report from the given text.

swearjar.scorecard( 'f-bomb you' ); // {sexual: 1, inappropriate: 1}

swearjar.addRegex(text)

Add a regex.

swearjar.addRegex( 'addedword?\\b', ['detected'] );

swearjar.addSimple(text)

Add a simple word.

swearjar.addSimple( 'addedword', ['detected'] );

swearjar.addEmoji(text)

Add an emoji word.

swearjar.addEmoji( '1f596', ['detected'] );

swearjar.loadBadWords(path)

Loads a dictionary of words to be used as filter.

NOTE: A US English default list located in the config directory is included and loaded by default.

swearjar.loadBadWords( './config/profanity.json' );

A dictionary is just a plain JSON file containing an object where its keys are the words to check for and the values are arrays of categories where the words fall in.

{
  "regex": {
    "\\w*fuck\\w*": [
      "category1",
      "category2"
    ],
    "word2": [
      "category1"
    ],
    "word3": [
      "category2"
    ]
  },
  "simple": {
    "word1": [
      "category1",
      "category2"
    ],
    "word2": [
      "category1"
    ],
    "word3": [
      "category2"
    ]
  },
  "emoji": {
    "1f4a9": [
      "category1",
      "category2"
    ],
    "word2": [
      "category1"
    ],
    "word3": [
      "category2"
    ]
  }
}

Acknowledgements

swearjar is based on swearjar-node, which itself is based on Swearjar (Ruby) and Swearjar PHP.

Here are all the versions for this package. Please note that you can leverage CommandBox package versioning to install any package you like. Please refer to our managing package version guide for more information.

Version Created Last Update Published By Stable Actions
Current
1.4.1 Nov 26 2019 08:13 AM Nov 26 2019 08:13 AM
Version History
1.4.0 Nov 25 2019 05:38 AM Nov 25 2019 05:38 AM
1.3.0 Nov 21 2019 02:24 AM Nov 21 2019 02:46 AM
1.2.0 Nov 19 2019 01:16 PM Nov 19 2019 01:16 PM
1.1.0 Nov 13 2019 04:24 AM Nov 13 2019 04:24 AM
1.0.0 Nov 12 2019 02:38 PM Nov 12 2019 02:38 PM

 

No collaborators yet.
   
  • Nov 12 2019 02:38 PM
  • Nov 26 2019 08:13 AM
  • 274
  • 16
  • 14