Home Reference Source
import WebPurify from 'webpurify/src/webpurify.js'
public class | source

WebPurify

WebPurify NPM Module A Node NPM module for interacting with the WebPurify API

Constructor Summary

Public Constructor
public

Member Summary

Private Members
private

_config: *

private

_query_base: {"api_key": *, "format": string}

private

_request_base: {"host": *, "path": *}

Method Summary

Public Methods
public

async addToBlacklist(word: string, ds: string): Promise

Add a word to the blacklist

public

async addToWhitelist(word: string, ds: string): Promise

Add a word to the whitelist

public

Check the number of AIM image submissions remaining on your license.

public

async aimImgCheck(imgurl: string): Promise

Checks the passed imageurl moderation.

public

async check(text: string, options: Object): Promise

Checks the passed text for any profanity.

public

async checkCount(text: string, options: Object): Promise

Checks the passed text for any profanity.

public

async get(params: Object, options: Object, host: Object): Promise

Formats the request for the request function

public

Get the blacklist

public

Get the whitelist

public

async hybridImgCheck(imgurl: string, options: Object): Promise

Combine our Automated Intelligent Moderation system (AIM) and our Live moderators to create a powerful low cost solution.

public

async imgAccount(): Promise

Checks the remaining submissions on licence for images.

public

async imgCheck(imgurl: string, options: Object): Promise

Checks the passed imageurl moderation.

public

async imgStatus(imgid: string, options: Object): Promise

Checks the imgid for status of moderation.

public

Remove a word from the blacklist

public

Remove a word from the whitelist

public

async replace(text: string, replacesymbol: string, options: Object): Promise

Checks the passed text for any profanity.

public

request(host: string, path: string, method: string, ssl: boolean): Promise

Handles the HTTP/S requests

public

async return(text: string, options: Object): Promise

Checks the passed text for any profanity.

public

strip(response: Object): Object

Strips the WebPurify JSON response to be useful

Public Constructors

public constructor(options: Object): WebPurify source

Params:

NameTypeAttributeDescription
options Object

Pass configuration options here, or declare them in their respective ENV variables.

options.api_key Object

WebPurify API Key. ENV variable (takes precedence): WEBPURIFY_API_KEY

options.endpoint Object

Available: 'us', 'eu', 'ap'. Default: 'us'. ENV variable: WEBPURIFY_ENDPOINT

options.enterprise Object

Available: true, false. Default: false. ENV varable: WEBPURIFY_ENTERPRISE

Return:

WebPurify

A WebPurify instance.

Throw:

Error

Throws an error if parameters are invalid.

Error

Throws an error if API key is missing.

Private Members

private _config: * source

private _query_base: {"api_key": *, "format": string} source

private _request_base: {"host": *, "path": *} source

Public Methods

public async addToBlacklist(word: string, ds: string): Promise source

Add a word to the blacklist

Params:

NameTypeAttributeDescription
word string

The word to add to the blacklist

ds string
  • optional
  • default: 0

1 if deepsearch, 0 or null if you don't care

Return:

Promise

public async addToWhitelist(word: string, ds: string): Promise source

Add a word to the whitelist

Params:

NameTypeAttributeDescription
word string

The word to add to the whitelist

ds string
  • optional
  • default: 0

1 if deepsearch, 0 or null if you don't care

Return:

Promise

public async aimImgAccount(): Promise source

Check the number of AIM image submissions remaining on your license.

Return:

Promise

public async aimImgCheck(imgurl: string): Promise source

Checks the passed imageurl moderation. It will need a callback.

Params:

NameTypeAttributeDescription
imgurl string

The URL of the image

Return:

Promise

public async check(text: string, options: Object): Promise source

Checks the passed text for any profanity. If found, returns true, else false.

Params:

NameTypeAttributeDescription
text string

The text to check for profanity

options Object
  • optional

The optional API parameters

options.lang Object
  • optional

The 2 letter language code for the text you are submitting

options.semail Object
  • optional

Treat email addresses like profanity. set = 1

options.sphone Object
  • optional

Treat phone numbers like profanity. set = 1

options.slink Object
  • optional

Treat urls like profanity. set = 1

options.rsp Object
  • optional

To include our response time in the result. set = 1

Return:

Promise

public async checkCount(text: string, options: Object): Promise source

Checks the passed text for any profanity. If found, returns number of found words, else 0.

Params:

NameTypeAttributeDescription
text string

The text to check for profanity

options Object
  • optional

The optional API parameters

options.lang Object
  • optional

The 2 letter language code for the text you are submitting

options.semail Object
  • optional

Treat email addresses like profanity. set = 1

options.sphone Object
  • optional

Treat phone numbers like profanity. set = 1

options.slink Object
  • optional

Treat urls like profanity. set = 1

options.rsp Object
  • optional

To include our response time in the result. set = 1

Return:

Promise

public async get(params: Object, options: Object, host: Object): Promise source

Formats the request for the request function

Params:

NameTypeAttributeDescription
params Object

The params object passed into the request

options Object
  • optional
  • default: {}

The optional parameters for the API request

host Object
  • optional
  • default: this._request_base.host

Optional request host

Return:

Promise

public async getBlacklist(ds: string): Promise source

Get the blacklist

Params:

NameTypeAttributeDescription
ds string
  • optional
  • default: 0

Set equal to 1 to show which of the blacklist items have “deep search” turned on.

Return:

Promise

public async getWhitelist(ds: string): Promise source

Get the whitelist

Params:

NameTypeAttributeDescription
ds string
  • optional
  • default: 0

Set equal to 1 to show which of the blacklist items have “deep search” turned on.

Return:

Promise

public async hybridImgCheck(imgurl: string, options: Object): Promise source

Combine our Automated Intelligent Moderation system (AIM) and our Live moderators to create a powerful low cost solution.

Images submitted to this method, are first sent to AIM and then sent to our live moderation team based on thresholds you set.

I.E any image that is given a 50% or greater probability by AIM can then be sent to our human moderation team for further review.

Params:

NameTypeAttributeDescription
imgurl string

The URL of the image

options Object
  • optional

The optional API parameters

options.thresholdlt Object
  • optional

Set the lower threshold to pass the image to our live team. E.g. thresholdlt=50 would send all images that AIM gives a nudity probability of less than 50 to our live team.

options.thresholdgt Object
  • optional

Set the upper threshold to pass the image to our live team. E.g. thresholdgt=70 would send all images that AIM gives a nudity probability of greater than 70 to our live team.

options.customimgid Object
  • optional

A custom ID you wish to associate with the image that will be carried through to the callback

options.callback Object
  • optional

You may also submit a URL encoded callback on a per image basis

Return:

Promise

public async imgAccount(): Promise source

Checks the remaining submissions on licence for images.

Return:

Promise

public async imgCheck(imgurl: string, options: Object): Promise source

Checks the passed imageurl moderation. It will need a callback.

Params:

NameTypeAttributeDescription
imgurl string

Full url to the image you would like moderated.

options Object
  • optional

The optional API parameters

options.customimgid Object
  • optional

A custom ID you wish to associate with the image that will be carried through to the callback

options.callback Object
  • optional

You may also submit a URL encoded callback on a per image basis

options.snstopic Object
  • optional

SNS Topic name. To use AWS SNS to receive results

options.photodna object
  • optional

Set = 1 to check images for matches against known child exploitation hash datasets – You must activate PhotoDNA for your API Key in your admin console.

Return:

Promise

public async imgStatus(imgid: string, options: Object): Promise source

Checks the imgid for status of moderation.

Params:

NameTypeAttributeDescription
imgid string

The URL of the image

options Object
  • optional

The optional API parameters

options.customimgid Object
  • optional

A custom ID you wish to associate with the image that will be carried through to the callback

Return:

Promise

public async removeFromBlacklist(word: string): Promise source

Remove a word from the blacklist

Params:

NameTypeAttributeDescription
word string

The word to remove from the blacklist

Return:

Promise

public async removeFromWhitelist(word: string): Promise source

Remove a word from the whitelist

Params:

NameTypeAttributeDescription
word string

The word to remove from the whitelist

Return:

Promise

public async replace(text: string, replacesymbol: string, options: Object): Promise source

Checks the passed text for any profanity. If found, returns the text with profanity altered by symbol. Else 0.

Params:

NameTypeAttributeDescription
text string

The text to check for profanity

replacesymbol string

The symbol to replace profanity with (ie. '*')

options Object
  • optional

The optional API parameters

options.lang Object
  • optional

The 2 letter language code for the text you are submitting

options.semail Object
  • optional

Treat email addresses like profanity. set = 1

options.sphone Object
  • optional

Treat phone numbers like profanity. set = 1

options.slink Object
  • optional

Treat urls like profanity. set = 1

options.rsp Object
  • optional

To include our response time in the result. set = 1

Return:

Promise

public request(host: string, path: string, method: string, ssl: boolean): Promise source

Handles the HTTP/S requests

Params:

NameTypeAttributeDescription
host string

The hostname for the request URL (ie. api1.webpurify.com)

path string

The path of the request (ie. /services/rest/)

method string

The method, either 'GET or 'PUT'

ssl boolean

True or false for using HTTPS or HTTP. If you are using enterprise API, you can set this to true.

Return:

Promise

public async return(text: string, options: Object): Promise source

Checks the passed text for any profanity. If found, returns an array of expletives.

Params:

NameTypeAttributeDescription
text string

The text to check for profanity

options Object
  • optional

The optional API parameters

options.lang Object
  • optional

The 2 letter language code for the text you are submitting

options.semail Object
  • optional

Treat email addresses like profanity. set = 1

options.sphone Object
  • optional

Treat phone numbers like profanity. set = 1

options.slink Object
  • optional

Treat urls like profanity. set = 1

options.rsp Object
  • optional

To include our response time in the result. set = 1

Return:

Promise

public strip(response: Object): Object source

Strips the WebPurify JSON response to be useful

Params:

NameTypeAttributeDescription
response Object

The response JSON to be stripped

Return:

Object

The stripped response