GithubHelp home page GithubHelp logo

divineomega / is_offensive Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 4.0 141 KB

🤬🤭 Is Offensive Helper Function - Check if a string contains offensive words or variations of them

License: GNU Lesser General Public License v3.0

PHP 100.00%
offensive-language php-library php-helper offensive php

is_offensive's Introduction

🤬🤭 Is Offensive Helper Function

Build Status Coverage Status StyleCI

This PHP package provides an is_offensive helper function. Passing a string to is_offensive will return a boolean telling you if it contains offensive words.

Installation

The is_offensive package can be easily installed using Composer. Just run the following command from the root of your project.

composer require "divineomega/is_offensive"

If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.

Usage

To check if a word is offensive, just pass it to the is_offensive method.

Here are a few examples:

is_offensive('fuck');  // true
is_offensive('fuk');   // true

is_offensive('duck');  // false
is_offensive('cat');   // false

is_offensive('sex');         // true
is_offensive('Middlesex');   // false

is_offensive('tit');         // true
is_offensive('Tittesworth'); // false

is_offensive('cunt');        // true
is_offensive('Scunthorpe');  // false

If you prefer to avoid using helper functions, the following syntax is also available.

$offensive = (new OffensiveChecker())->isOffensive('fuck')  // true

Custom word lists

There are reasons why you may wish to define your own list of offensive words. Perhaps the ones supplied are too strict, or not strict enough.

$blacklist = ['moist', 'stinky', 'poo'];

$offensiveChecker = new OffensiveChecker($blacklist);

$offensiveChecker->isOffensive('poo');     // true
$offensiveChecker->isOffensive('poops');   // true

You can also define a whitelist of words that will be accepted even if they match the defined list of offensive words.

$blacklist = ['moist', 'stinky', 'poo'];
$whitelist = ['poop'];

$offensiveChecker = new OffensiveChecker($blacklist, $whitelist);

$offensiveChecker->isOffensive('poo');     // true
$offensiveChecker->isOffensive('poops');   // false

is_offensive's People

Contributors

divineomega avatar peter279k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

is_offensive's Issues

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.