Lyo.Profanity
2.0.1
dotnet add package Lyo.Profanity --version 2.0.1
NuGet\Install-Package Lyo.Profanity -Version 2.0.1
<PackageReference Include="Lyo.Profanity" Version="2.0.1" />
<PackageVersion Include="Lyo.Profanity" Version="2.0.1" />
<PackageReference Include="Lyo.Profanity" />
paket add Lyo.Profanity --version 2.0.1
#r "nuget: Lyo.Profanity, 2.0.1"
#:package Lyo.Profanity@2.0.1
#addin nuget:?package=Lyo.Profanity&version=2.0.1
#tool nuget:?package=Lyo.Profanity&version=2.0.1
Lyo.Profanity
File-based profanity filter. Finds and replaces profane words. Several languages, regex patterns, plain word lists, and configurable replacement strategies.
Features
- Word sources. JSON file, HTTP URL, or per-language
WordsByLanguage - Format support. Structured JSON (
[{ id, match, tags, severity, exceptions }]), plain array["word1", "word2"], or plain newline-separated text (one word per line) - Replacement strategies.
Remove,ReplaceWithChar,ReplaceWithWord,Mask,PreserveBoundary,DetectOnly - Per-language. Load different word lists by BCP 47 / ISO 639-1 / ISO 639-3
Examples
Register and filter
services.AddProfanityFilterService(options =>
{
options.WordsFilePath = "profanity-words.json";
options.ReplacementStrategy = ProfanityReplacementStrategy.Mask;
});
// Or bind from configuration
services.AddProfanityFilterServiceFromConfiguration(configuration, "ProfanityFilter");
// In a service
var result = await _profanityFilter.FilterAsync("some text with bad word", ct);
// result.FilteredText, result.HasProfanity, result.Matches
Configuration (appsettings.json)
{
"ProfanityFilter": {
"WordsFilePath": "profanity-en.json",
"WordsUrl": "https://example.com/words.json",
"ReplacementStrategy": "Mask",
"Language": "en-US",
"AllowRefresh": true,
"WordsByLanguage": {
"en": { "WordsFilePath": "en.json" },
"es": { "WordsFilePath": "es.json" }
}
}
}
Service registration
Lyo.Profanity.Extensions exposes three entry points on IServiceCollection. Choose exactly one when wiring the host:
| Entry point | Behaviour |
|---|---|
services.AddProfanityFilterService() |
Registers a default FileProfanityFilterOptions and FileProfanityFilterService (resolved as both itself and IProfanityFilterService). Useful in tests that only need the methods. |
services.AddProfanityFilterService(Action<FileProfanityFilterOptions> configure) |
The same registration, with an inline options callback. |
services.AddProfanityFilterServiceFromConfiguration(IConfiguration configuration, string sectionName = FileProfanityFilterOptions.SectionName) |
The same registration, binding options from the configuration section (default "ProfanityFilter"). |
FileProfanityFilterService resolves an optional ILogger<FileProfanityFilterService>, an optional IMetrics (used only when Options.EnableMetrics == true), and an optional HttpClient (used when WordsUrl is configured).
IProfanityFilterService methods
Filter(string? input, CancellationToken)/Filter(string? input, LanguageCodeInfo language, CancellationToken)synchronous filtering. ReturnsProfanityFilterResult(FilteredText,HasProfanity,Matches).FilterAsync(string? input, CancellationToken)/FilterAsync(string? input, LanguageCodeInfo language, CancellationToken)the same, async.ContainsProfanity(string? input, CancellationToken)/ContainsProfanity(string? input, LanguageCodeInfo language, CancellationToken)fast boolean check, no replacement.ContainsProfanityAsync(string? input, CancellationToken)/ContainsProfanityAsync(string? input, LanguageCodeInfo language, CancellationToken)async variants.RefreshWords(CancellationToken)/RefreshWordsAsync(CancellationToken)reload from the configured file/URL. No-op whenOptions.AllowRefreshis false or the source doesn't support refresh.
Word list formats
- Plain JSON array.
["word1", "word2"]becomes default entries (id == match == word,tags = [],severity = 1,exceptions = []). - Structured JSON.
[{ "id": "x", "match": "regex|word", "tags": [], "severity": 1, "exceptions": [] }].matchis compiled as aRegexand cached. - Plain newline-separated text. One word per line, same defaults as the plain JSON array.
Replacement strategies
| Strategy | Example (input → output) |
|---|---|
| Remove | "bad" → "" |
| ReplaceWithChar | "bad" → "***" |
| ReplaceWithWord | "bad" → "***" |
| Mask | "bad" → "***" |
| PreserveBoundary | "bad" → "b*d" |
| DetectOnly | No replacement; only detect |
Dependencies
Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).
Lyo.Common.Metadata(direct, lyo)Lyo.Exceptions(direct, lyo)Lyo.Metrics(direct, lyo)Microsoft.Extensions.Configuration.Binder10.0.5(direct, microsoft)Microsoft.Extensions.DependencyInjection.Abstractions10.0.5(direct, microsoft)Microsoft.Extensions.Logging.Abstractions10.0.5(direct, microsoft)Microsoft.Extensions.Options10.0.5(direct, microsoft)System.Text.Json10.0.5(direct, microsoft, netstandard2.0)Lyo.Common.Core(transitive, lyo)Microsoft.Bcl.AsyncInterfaces10.0.5(transitive, microsoft, netstandard2.0)System.Memory4.6.3(transitive, microsoft, netstandard2.0)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Lyo.Common.Metadata (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Metrics (>= 2.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Options (>= 10.0.5)
- System.Text.Json (>= 10.0.5)
-
net10.0
- Lyo.Common.Metadata (>= 2.0.0)
- Lyo.Exceptions (>= 2.0.0)
- Lyo.Metrics (>= 2.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- Microsoft.Extensions.Options (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.