Awesome
<p align="center"> <img src="./assets/icon.png" alt="Blasp Icon" width="150" height="150"/> <p align="center"> <a href="https://github.com/Blaspsoft/blasp/actions/workflows/main.yml"><img alt="GitHub Workflow Status (main)" src="https://github.com/Blaspsoft/blasp/actions/workflows/main.yml/badge.svg"></a> <a href="https://packagist.org/packages/blaspsoft/blasp"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/blaspsoft/blasp"></a> <a href="https://packagist.org/packages/blaspsoft/blasp"><img alt="Latest Version" src="https://img.shields.io/packagist/v/blaspsoft/blasp"></a> <a href="https://packagist.org/packages/blaspsoft/blasp"><img alt="License" src="https://img.shields.io/packagist/l/blaspsoft/blasp"></a> </p> </p>Blasp - Profanity Filter for Laravel
Blasp is a profanity filter package for Laravel that helps detect and mask profane words in a given sentence. It offers a robust set of features for handling variations of offensive language, including substitutions, obscured characters, and doubled letters.
Installation
You can install the package via Composer:
composer require blaspsoft/blasp
Usage
Basic Usage
To use the profanity filter, simply call the Blasp::check()
method with the sentence you want to check for profanity.
use Blaspsoft\Blasp\Facades\Blasp;
$sentence = 'This is a fucking shit sentence';
$check = Blasp::check($sentence);
you can also change the default language to french
use Blaspsoft\Blasp\Facades\Blasp;
$sentence = 'Cette phrase est merdique';
$check = Blasp::check($sentence, 'fr');
The returned object will contain the following properties:
- sourceString: The original string you passed.
- cleanString: The string with profanities masked (e.g., replaced with
*
). - hasProfanity: A boolean indicating whether the string contains profanity.
- profanitiesCount: The number of profanities found.
- uniqueProfanitiesFound: An array of unique profanities found in the string.
Example
$sentence = 'This is a fucking shit sentence';
$blasp = Blasp::check($sentence);
$blasp->getSourceString(); // "This is a fucking shit sentence"
$blasp->getCleanString(); // "This is a ******* **** sentence"
$blasp->hasProfanity(); // true
$blasp->getProfanitiesCount(); // 2
$blasp->getUniqueProfanitiesFound(); // ['fucking', 'shit']
Profanity Detection Types
Blasp can detect different types of profanities based on variations such as:
- Straight match: Direct matches of profane words.
- Substitution: Substituted characters (e.g.,
pro0fán1ty
). - Obscured: Profanities with separators (e.g.,
p-r-o-f-a-n-i-t-y
). - Doubled: Repeated letters (e.g.,
pprrooffaanniittyy
). - Combination: Combinations of the above (e.g.,
pp-rof@n|tty
).
Laravel Validation Rule
Blasp also provides a custom Laravel validation rule called blasp_check
, which you can use to validate form input for profanity.
Example
$request->merge(['sentence' => 'This is f u c k 1 n g awesome!']);
$validated = $request->validate([
'sentence' => ['blasp_check'],
]);
// If the sentence contains profanities, validation will fail.
or for french
$validated = $request->validate([
'sentence' => ['blasp_check:fr'],
]);
Configuration
Blasp uses a configuration file (config/blasp.php
) to manage the list of profanities, separators, and substitutions. You can publish the configuration file using the following Artisan command:
php artisan vendor:publish --tag="blasp-config"
License
Blasp is open-sourced software licensed under the MIT license.