profanity_filter 1.0.0 profanity_filter: ^1.0.0 copied to clipboard
Simple class to create filters that check and censor strings against profanity. A default English words list is provided.
import 'package:profanity_filter/profanity_filter.dart';
void main() {
//Create the filter - default, so it uses the default English profanity list.
final filter =
ProfanityFilter(); //Other constructors are available, see README.
String badString =
'You are an ass'; //This string contains the profanity 'ass'
//Check for profanity - returns a boolean (true if profanity is present)
bool isStringProfane =
filter.checkStringForProfanity(badString); //Returns 'true'
print('The string $badString has profanity: $isStringProfane');
//Get the profanity used - returns a List<String>
List<String> profanityUsed = filter.getAllProfanityInString(badString);
print(profanityUsed); //['ass']
//Censor the string - returns a 'cleaned' string.
String cleanString = filter.censorString(badString);
print('Clean version of $badString is $cleanString');
}