Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xavier/expletive
Profanity filter library for Elixir
https://github.com/xavier/expletive
Last synced: about 1 month ago
JSON representation
Profanity filter library for Elixir
- Host: GitHub
- URL: https://github.com/xavier/expletive
- Owner: xavier
- License: apache-2.0
- Created: 2015-02-14T20:38:28.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-07-01T13:20:14.000Z (over 2 years ago)
- Last Synced: 2024-10-04T01:18:54.199Z (2 months ago)
- Language: Elixir
- Size: 31.3 KB
- Stars: 41
- Watchers: 4
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Profanity filter library for Elixir. (Text and Numbers)
- fucking-awesome-elixir - expletive - Profanity filter library for Elixir. (Text and Numbers)
- awesome-elixir - expletive - Profanity filter library for Elixir. (Text and Numbers)
README
# Expletive
An obscenity detection and filtering library for Elixir, freely inspired by the [obscenity gem](https://github.com/tjackiw/obscenity).
## Installation
Add Expletive as a dependency to your project `mix.exs`:
```Elixir
def deps do
[{:expletive, "~> 0.1.0"}]
end```
## Usage
All Expletive functions expect a configuration to be passed:
```Elixir
config = Expletive.configure(blacklist: ~w[very bad words])
Expletive.profane?("this is bad!", config)
# => true
Expletive.profane?("perfectly safe", config)
# => falseExpletive.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.
```Elixir
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:
```Elixir
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:
```Elixir
config = Expletive.configure(blacklist: Expletive.Blacklist.english)
Expletive.profane?("this is batshit crazy!", config)
# => trueconfig = 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.