Git Product home page Git Product logo

profanity_filter's Introduction

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.

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.

profanity_filter's People

Contributors

roshanrahman avatar

Watchers

James Cloos avatar

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.