safe_text 3.0.0 copy "safe_text: ^3.0.0" to clipboard
safe_text: ^3.0.0 copied to clipboard

A fast Dart profanity & swear word filter with phone number detection, powered by Aho-Corasick. Supports 80+ languages and 55,000+ curated bad words.

example/lib/main.dart

import 'dart:io';

import 'package:safe_text/safe_text.dart';

Future<void> main() async {
  SafeTextFilter.init(language: Language.english);

  stdout.writeln('SafeText — Dart CLI demo');
  stdout.writeln('Profanity filtering + bad-word and phone-number detection.');
  stdout.writeln('Type a sentence and press Enter. Press Enter on an empty');
  stdout.writeln('line or type "quit" to exit.');
  stdout.writeln();

  const sample = 'This is a shitty example with 123-456-7890.';
  stdout.writeln('Sample text : $sample');
  stdout.writeln('Full mask   : '
      '${SafeTextFilter.filterText(text: sample, strategy: MaskStrategy.full())}');
  stdout.writeln('Partial mask: '
      '${SafeTextFilter.filterText(text: sample, strategy: MaskStrategy.partial())}');
  stdout.writeln('Custom mask : '
      '${SafeTextFilter.filterText(text: sample, strategy: MaskStrategy.custom(replacement: '[censored]'))}');
  stdout.writeln();
  stdout.writeln('Now type your own input:');
  stdout.writeln();

  while (true) {
    stdout.write('> ');
    final line = stdin.readLineSync();
    if (line == null) break;

    final input = line.trim();
    if (input.isEmpty || input.toLowerCase() == 'quit') break;

    final filtered = SafeTextFilter.filterText(text: input);
    final hasBadWord = SafeTextFilter.containsBadWord(text: input);
    final hasPhoneNumber =
        await PhoneNumberChecker.containsPhoneNumber(text: input);

    stdout.writeln('Filtered      : $filtered');
    stdout.writeln('Contains bad word  : ${hasBadWord ? 'yes' : 'no'}');
    stdout.writeln('Contains phone no. : ${hasPhoneNumber ? 'yes' : 'no'}');
    stdout.writeln();
  }

  stdout.writeln('Goodbye!');
}
65
likes
160
points
2.42k
downloads
screenshot

Documentation

Documentation
API reference

Publisher

unverified uploader

Weekly Downloads

A fast Dart profanity & swear word filter with phone number detection, powered by Aho-Corasick. Supports 80+ languages and 55,000+ curated bad words.

Repository (GitHub)
View/report issues
Contributing

Topics

#text-processing #profanity-filter #phone-number-detection #content-moderation #flutter

Funding

Consider supporting this project:

www.buymeacoffee.com

License

MIT (license)

More

Packages that depend on safe_text