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/.
npm install webpurify
To initialize:
var WebPurify = require('webpurify');
var wp = new WebPurify({
api_key: 'my_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
});Check a string of text for profanity. Returns true if profanity found, false if none.
wp.check('some profane text', function(err, profanity) {
if (profanity===true) {
console.log('A bunch of sailors in here!');
} else {
console.log('This is a pure string');
}
});Check a string of text for profanity. Returns number of words if profanity found, 0 if none.
wp.checkCount('some profane text', function(err, profanity) {
if (profanity > 0) {
console.log(profanity.toString() + ' sailors in here!');
} else {
console.log('This is a pure string');
}
});wp.replace('some profane text', '*', function(err, purified_text) {
console.log(purified_text);
});wp.return('some profane text', function(err, 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, function(error, profanity) {
console.log(profanity);
});wp.addToBlacklist('my_word', function(err, success) {
if (success===true) 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);wp.removeFromBlacklist('my_word', function(err, success) {
if (success===true) console.log('success!');
});Can also be called without callback:
wp.removeFromBlacklist('my_word');wp.getBlacklist(function(err, blacklist) {
for (word in blacklist) {
console.log(blacklist[word]);
}
});wp.addToWhitelist('my_word', function(err, success) {
if (success===true) console.log('success!');
});Can also be called without callback:
wp.addToWhitelist('my_word');wp.removeFromWhitelist('my_word', function(err, success) {
if (success===true) console.log('success!');
});Can also be called without callback:
wp.removeFromWhitelist('my_word');wp.getWhitelist(function(err, whitelist) {
for (word in whitelist) {
console.log(whitelist[word]);
}
});So far it mimics the WebPurify API as closely as possible. If you find bugs or want to contribute, please do, that would be amazing.