profanity_filter 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

profanity_filter #

Simple Dart class to create filters that check and censor strings against profanity. A default English words list is provided.

Usage #

To use this plugin, add profanity_filter as a dependency in your pubspec.yaml file.

Example #

import 'package:profanity_filter/profanity_filter.dart';

void main() {
  final filter = ProfanityFilter(); //Creates filter with default list.
  String myString = 'you are an ass';

  //To check if profanity exists
  bool isProfane = filter.checkStringForProfanity(
      myString); //Returns true since 'ass' is in profanity list.
  if (isProfane) {
    print('Profanity was detected');
  }

  //To censor a string
  String cleanString = filter.censorString(myString);
  print(cleanString); //Prints 'you are an ***'
}

Detect if a string contains profanity #

Use the checkStringForProfanity() method of the filter instance. Pass in the string to be tested.

Example #

final filter = ProfanityFilter();
String badString = 'you are an ass';
filter.checkStringForProfanity(badString); //Returns true.

Return the list of profanity used #

If you want to get all the profane words used in the string, use the getAllProfanityInString() method.

Example #

final filter = ProfanityFilter();
String badString = 'you are an ass';
filter.getAllProfanityInString(badString); //Returns ['ass'].

Censor a string (replace profanity with something clean) #

Use the censorString() method of the filter instance. Pass in the string to be censored.

Example #

final filter = ProfanityFilter();
String badString = 'you are an ass';
String cleanString = filter.censorString('you are an ass'); //cleanString: 'you are an ***'

Optionally, you can provide your own clean replacement word to the replaceWith named parameter. filter.censorString(string, replaceWith:'[censored]') will replace any profanity in string with [censored]

Default Profanity List #

The default profanity list is taken from the LDNOOBW list, licensed under a Creative Commons Attribution 4.0 International License.

To create a filter with the default list, use the default constructor ProfanityFilter()

Variations #

To include custom words alongside default list #

Use ProfanityFilter.filterAdditionally() constructor and pass your list of custom words.

To filter only custom words (default list is ignored) #

Use ProfanityFilter.filterOnly() constructor and pass your list of custom words.

To filter with a few exclusions from default list #

Use ProfanityFilter.ignore() constructor and pass your list of custom words. Those words will be removed from the default list if they exist there.

[1.0.2] - Fixed Description

  • Updated package description

[1.0.1] - Fixed Dart SDK Constraints

  • Updated package description
  • Fixed Dart SDK constraints in pubspec.yaml

[1.0.0] - Initial release.

Initial release

example/main.dart

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');
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  profanity_filter: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:profanity_filter/profanity_filter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Nov 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:profanity_filter/profanity_filter.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
Dev dependencies
test any