Git Product home page Git Product logo

expletive's Introduction

Expletive

An obscenity detection and filtering library for Elixir, freely inspired by the obscenity gem.

Installation

Add Expletive as a dependency to your project mix.exs:

def deps do
  [{:expletive, "~> 0.1.0"}]
end

Usage

All Expletive functions expect a configuration to be passed:

config = Expletive.configure(blacklist: ~w[very bad words])

Expletive.profane?("this is bad!", config)
# => true
Expletive.profane?("perfectly safe", config)
# => false

Expletive.profanities("this is bad, so BAD!", config)
# => ["bad", "BAD"]

Sanitization

The library offers a fairly wide variety of profanity replacement strategies which can be defined at configuration time or passed explicitly.

Expletive.sanitize("this is bad, so BAD!", config)
# => "This is $#!@%, so %$@!#!"

Expletive.sanitize("this is bad, so BAD!", config, :stars)
# => "This is ***, so ***!"

Expletive.sanitize("this is bad, so BAD!", config, :vowels)
# => "This is b*d, so B*D!

Expletive.sanitize("this is bad, so BAD!", config, ":poop:")
# => "This is :poop:, so :poop:!

Expletive.sanitize("this is bad, so BAD!", config, {:repeat, "-"})
# => "This is ---, so ---!

Expletive.sanitize("this is bad, so BAD!", config, :keep_first_letter)
# => "This is b**, so B**!

Expletive.sanitize("this is bad, so BAD!", config, {:keep_first_letter, "-"})
# => "This is b--, so B--!

Whitelisting

If you wish to allow some words present in the blacklist, you can add exceptions to a whitelist at configuration time:

config = Expletive.configure(blacklist: ~w[very bad words], whitelist: ~w[words])

Expletive.profane?("words", config)
# => false

Built-in blacklists

The library comes with a couple of word lists ready to use:

config = Expletive.configure(blacklist: Expletive.Blacklist.english)

Expletive.profane?("this is batshit crazy!", config)
# => true

config = Expletive.configure(blacklist: Expletive.Blacklist.international)

Expletive.profanities("ceci n'est pas une pipe", config)
# => ["pipe"]

Known Limitations

I18n concerns

A couple of replacement strategies (:vowels and :nonconsonants) are currently limited to the english language.

expletive's People

Contributors

benfalk avatar leikind avatar ronaldcurtis avatar xavier avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.