Skip to content

gmemstr/no-swears

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

no-swears

Automagically filter out swear words in strings

npm version

Very simple package for censoring swear words from JavaScript strings, replacing offending words with "****".

Usage

npm install --save no-swears
"use strict";

const noswears = require("no-swears");

filterSwearWords(string, callback)

This is the most basic filtering function, and requires the offending string and a callback, returning the cleaned up string to the program.

let badString = "this is a bitching string";

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

hasSwears(string, callback)

This just returns true or false to callback depending on whether the passed string contains a swear word

let badString = "this is a bitching string";

noswears.hasSwears(badString, (swearBool) => {
  console.log(swearBool); // true
});

hasSwearsSync(string)

This just returns true or false synchronously to be used in true/false conditions

let badString = "this is a bitching string";

if (noswears.hasSwearsSync(badString)) {
  console.log("Has swears!"); // "Has swears"!
}

About

Clean up your JavaScript strings and remove those filthy words.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published