Skip to content

A node module for interacting with the WebPurify API.

License

Notifications You must be signed in to change notification settings

jesse-mm/webpurify

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebPurify API for Node.js

This module allows simple interaction with the WebPurify API within Node.js. For more information about WebPurify and the services it offers, check out http://webpurify.com/.

Commands

Filters
Blacklist
Whitelist

Install & Initialize

npm install webpurify

To initialize:

var WebPurify = require('webpurify');

var wp = new WebPurify({
    api_key: ENV['WEBPURIFY_API_KEY']
    //, endpoint:   'us'  // Optional, available choices: 'eu', 'ap'. Default: 'us'.
    //, enterprise: false // Optional, set to true if you are using the enterprise API, allows SSL
});

Commands

### check

Check a string of text for profanity. Returns true if profanity found, false if none.

wp.check('some profane text')
.then(profanity) {
  if (profanity) {
    console.log('A bunch of sailors in here!');
  } else {
    console.log('This is a pure string');
  }
});
### checkCount

Check a string of text for profanity. Returns number of words if profanity found, 0 if none.

wp.checkCount('some profane text')
.then(function(profanity) {
  if (profanity > 0) {
    console.log(profanity.toString() + ' sailors in here!');
  } else {
    console.log('This is a pure string');
  }
});
### replace Check a string of text for profanity. Replaces any found profanity with a provided symbol, and returns the formatted string.
wp.replace('some profane text', '*')
.then(function(purified_text) {
  console.log(purified_text);
});
### return Check a string of text for profanity. If any found, returns an array of profane words. Else, returns empty array.
wp.return('some profane text')
.then(function(profanity) {
  for (word in profanity) {
    console.log(profanity[word]);
  }
});

All filter commands can take an additional options object, just before the callback. The available options are:

var optional = {
  lang:   'en', // the 2 letter language code for the text you are submitting
  semail: 1,    // treat email addresses like profanity
  sphone: 1,    // treat phone numbers like profanity
  slink:  1     // treat urls like profanity
};

wp.check('some profane text', optional)
.then(function(profanity) {
  console.log(profanity);
});
### addToBlacklist Add a word to the blacklist.
wp.addToBlacklist('my_word')
.then(function(success) {
  if (success) console.log('success!');
});

Can also be called without callback:

wp.addToBlacklist('my_word');

For Deep search, add optional parameter 1 after word:

wp.addToBlacklist('my_word', 1);
### removeFromBlacklist Remove a word from the blacklist.
wp.removeFromBlacklist('my_word')
.then(function(success) {
  if (success) console.log('success!');
});

Can also be called without callback:

wp.removeFromBlacklist('my_word');
### getBlacklist Get the blacklist as an array of words.
wp.getBlacklist()
.then(function(blacklist) {
  for (word in blacklist) {
    console.log(blacklist[word]);
  }
});
### addToWhitelist Add a word to the whitelist.
wp.addToWhitelist('my_word')
.then(function(success) {
  if (success) console.log('success!');
});

Can also be called without callback:

wp.addToWhitelist('my_word');
### removeFromWhitelist Remove a word from the whitelist.
wp.removeFromWhitelist('my_word')
.then(function(success) {
  if (success) console.log('success!');
});

Can also be called without callback:

wp.removeFromWhitelist('my_word');
### getWhitelist Get the whitelist as an array of words.
wp.getWhitelist()
.then(function(whitelist) {
  for (word in whitelist) {
    console.log(whitelist[word]);
  }
});

v1.0.0

  • The WebPurify module is now written in ES6, using babel + babel-runtim to convert into ES5.
  • Now uses promises

About

A node module for interacting with the WebPurify API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%