Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple languages #6

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
**.DS_Store
**.DS_Store
.vscode
coverage
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- "5"
- "5.1"
- "4"
- "4.2"
- "4.1"
- "4.0"
after_success: 'npm run coveralls'
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Node.js Profanity Utility

[![Build Status](https://travis-ci.org/wagoid/nodejs-profanity-util.svg?branch=master)](https://travis-ci.org/wagoid/nodejs-profanity-util)
[![Coverage Status](https://coveralls.io/repos/github/wagoid/nodejs-profanity-util/badge.svg?branch=master)](https://coveralls.io/github/wagoid/nodejs-profanity-util?branch=master)

> Utility for detection, filtering and replacement / obscuration of forbidden words

The original list of swearwords used by default was taken from [here](https://gist.github.com/jamiew/1112488).
The original lists of swearwords used by default were taken from [here](https://gist.github.com/jamiew/1112488) and [here](https://github.com/shutterstock/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words).

**Please note:** This small utility module is written to prevent or monitor the use of certain words in your content without keeping context in account. An improper use may compromise the meaning of your content. Keep in account when using.

Expand All @@ -12,13 +15,15 @@ The original list of swearwords used by default was taken from [here](https://gi

## API

### `profanity.check(target_string, [ forbidden_list ])`
### `profanity.check(target_string, [languages], [ forbidden_list ])`
#####async version is also available: `profanity.checkAsync(target_string, [languages], [ forbidden_list ])`

Returns a list of forbidden words found in a string.

**Arguments**

* `target_string` - String to search
* `languages` (Optional )- Array of languages to check words from. Accepts a string if just one language is needed.
* `forbidden_list` (Optional) - Array containing forbidden terms

**Example**
Expand All @@ -30,7 +35,24 @@ console.log(profanity.check('Lorem ipsum foo bar poop test poop damn dolor sit..
// [ 'poop', 'poop', 'damn' ]
```

Or the async method:

```javascript
var profanity = require('profanity-util');

profanity.checkAsync('Lorem ipsum foo bar poop test poop damn dolor sit..')
.then(function (result) {
console.log(result);
// [ 'poop', 'poop', 'damn' ]
})
.catch(function (err) {
console.log('Something went wrong.');
});
```


### `profanity.purify(target, [ options ])`
#####async version is also available: `profanity.purifyAsync(target, [ options ])`

Purifies a string or strings contained in a given object or array from forbidden words.

Expand All @@ -51,9 +73,11 @@ The .purify method will return an Array containing two values:
**Options**

* `forbiddenList` - Array of forbidden terms to replace or obscure
* `languages` - Array of languages to check words from. Accepts a string if just one language is needed.
* `replacementsList` - Array of replacement words (To pick randomly from)
* `obscureSymbol` - Symbol used to obscure words if `obscured` is set to true
* `replace`- If set to true it will replace forbidden words (E.g. a*****b) instead of obscuring them
* `maxRecursionDepth` - If you are passing objects, a recursive iteration will be performed to fiind all strings inside it. You can set the maximum depth of the recursion.

**Examples**

Expand All @@ -72,6 +96,21 @@ console.log(profanity.purify({
// [ { foo: 'p**p', bar: { nested: 'd**n', arr: [ 'foo', 'p**p' ] } }, [ 'poop', 'damn', 'poop' ] ]
```

Async version:

```javascript
var profanity = require('profanity-util');

profanity.purify('lorem ipsum foo damn bar poop')
.then(function (result) {
console.log(result);
// [ 'lorem ipsum foo d**n bar p**p, [ 'damn', 'poop' ] ]
})
.catch(function (err) {
console.log('Something went wrong.');
});
```

**Obscure mode, custom options**

```javascript
Expand Down
Loading