Expletive

A profanity detection and sanitization library.

Source

Summary

configure(options)

Returns a configuration to pass to other functions

configure(config, options)

Updates the configuration. Accepts the same options as configure/1

profane?(string, config)

Returns true if the given string contains a word considered profane by the given configuration

profanities(string, config)

Returns a list of profanities found in the given string. All occurences are returned, duplicates may thus occur

sanitize(string, config)

Replace all profanities by a placeholder as defined by the replacement option of the current configuration

sanitize(string, config, replacement)

Replace all profanities by a placeholder as defined by the given replacement strategy

Types

replacement :: :default | :garbled | :stars | :vowels | :nonconsonants | String.t | {:repeat, String.t} | :keep_first_letter | {:keep_first_letter, String.t}

Functions

configure(options)

Specs:

  • configure(list) :: Expletive.Configuration.t

Returns a configuration to pass to other functions.

  • :blacklist - A list of words which are considered profane (if a string is given, it will be split on whitespace to create the world list)
  • :whitelist - A list of words which are allowed even if they’re also present in the blacklist (if a string is given, it will be split on whitespace to create the world list)
  • :replacement - A replacement strategy:

    • :garbled - Replace by a random permutation of $@!#% (default)
    • :stars - Replace all characters by *
    • :vowels - Replace all vowels of the offending word by *
    • :nonconsonants - Replace all non-consonants of the offending word by *
    • string - Replace the occurence by the given string
    • {:repeat, string} - Replace all characters by the given string
    • :keep_first_letter - Replace all characters but the first one by *
    • {:keep_first_letter, string} - Replace all characters but the first one by the given string
Source
configure(config, options)

Specs:

  • configure(Expletive.Configuration.t, list) :: Expletive.Configuration.t

Updates the configuration. Accepts the same options as configure/1

Source
profane?(string, config)

Specs:

  • profane?(String.t, Expletive.Configuration.t) :: boolean

Returns true if the given string contains a word considered profane by the given configuration

Source
profanities(string, config)

Specs:

Returns a list of profanities found in the given string. All occurences are returned, duplicates may thus occur

Source
sanitize(string, config)

Specs:

Replace all profanities by a placeholder as defined by the replacement option of the current configuration

Source
sanitize(string, config, replacement)

Specs:

Replace all profanities by a placeholder as defined by the given replacement strategy

Source