GSalvi.Toolkit 0.1.0-beta.20250326233608

This is a prerelease version of GSalvi.Toolkit.
dotnet add package GSalvi.Toolkit --version 0.1.0-beta.20250326233608
                    
NuGet\Install-Package GSalvi.Toolkit -Version 0.1.0-beta.20250326233608
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GSalvi.Toolkit" Version="0.1.0-beta.20250326233608" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GSalvi.Toolkit" Version="0.1.0-beta.20250326233608" />
                    
Directory.Packages.props
<PackageReference Include="GSalvi.Toolkit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GSalvi.Toolkit --version 0.1.0-beta.20250326233608
                    
#r "nuget: GSalvi.Toolkit, 0.1.0-beta.20250326233608"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GSalvi.Toolkit@0.1.0-beta.20250326233608
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GSalvi.Toolkit&version=0.1.0-beta.20250326233608&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=GSalvi.Toolkit&version=0.1.0-beta.20250326233608&prerelease
                    
Install as a Cake Tool

GSalvi.Toolkit

CI - Build and Test CD - Publish and Sync to Main NuGet Version

GSalvi.Toolkit is a versatile .NET utility library that brings together a set of helpers and extension methods to accelerate your development. This package includes:

  • String Extensions: Remove diacritics, specific characters, duplicate spaces, and non-alphanumeric characters.
  • Logging Utilities: Easily add custom properties to your Serilog logs with a fluent builder.
  • Notification Management: Create and manage notifications (both simple and localized) with immutable notification records.
  • Validators: Validate strings for allowed characters, digits, letters, and email addresses.

📦 Features

🔠 String Extensions

  • RemoveDiacritics: Strips accents and diacritics from text.
  • RemoveSpecificChars: Removes only the specified characters from a string.
  • RemoveCharsNotIn: Keeps only characters from an allowed set.
  • RemoveDuplicateSpaces: Eliminates duplicate spaces, leaving only a single space between words.
  • RemoveNonAlphanumeric: Filters out non-alphanumeric characters with the option to allow additional characters.

🔧 Logging Utilities

  • LogEnricherBuilder: Build custom enrichers for Serilog easily by adding key/value pairs that will be attached to your logs.

🔔 Notification Management

  • NotificationManager: Manages simple notifications.
  • LocalizedNotificationManager: Supports localized notifications using ASP.NET Core's localization features.

✅ Validators

  • CharsValidator: Check if a string contains only allowed characters, only digits, or only letters.
  • EmailValidator: Validate email addresses using a robust, pre-compiled regular expression.

⚙️ Installation

Install the package via the NuGet Package Manager using:

Install-Package Sozo.Toolkit

Or with the .NET CLI:

dotnet add package Sozo.Toolkit

🚀 Usage Examples

1. String Extensions

using Sozo.Toolkit.Extensions;

string accentedText = "Às ínclitas maçãs, o coração exibia êxtase, paixão e júbilo; já a fênix, à luz do pôr-do-sol, encantava o céu.";
string plainText = accentedText.RemoveDiacritics(); // Returns: "As inclitas macas, o coracao exibia extase, paixao e jubilo; ja a fenix, a luz do por-do-sol, encantava o ceu."

string textWithVowels = "Às ínclitas maçãs";
string withoutVowels = textWithVowels.RemoveSpecificChars('a', 'e', 'i', 'o', 'u'); // Returns: "Às ínclts mçãs"

string textWithDuplicates = "Às  ínclitas      maçãs";
string cleanedText = textWithDuplicates.RemoveDuplicateSpaces(); // Returns: "Às ínclitas maçãs"

string mixedText = "Às ínclitas maçãs, 123!.";
string alphaNumericOnly = mixedText.RemoveNonAlphanumeric(); // Returns: "Àsínclitasmaçãs123"

Creating a slug:

var slug = userName
    .ToLower()
    .Trim()
    .RemoveDuplicateSpaces()
    .RemoveDiacritics()
    .Replace(" ", "-")
    .RemoveNonAlphanumeric(allow: "-");

2. Logging with Serilog

using Serilog;
using Sozo.Toolkit.Logging;

using (LogContext.Push(new LogEnricherBuilder()
    .WithProperty("Application", "MyApp")
    .WithProperty("UseCase", "MyUseCase"))
{
    // All logs within using block are automatically logged with the Application and UseCase properties.
}

3. Notification Management

Simple Notifications
using Sozo.Toolkit.Notifications;

var notificationManager = new NotificationManager();
notificationManager.AddNotification("Operation completed successfully.");

if (notificationManager.HasNotifications)
{
    foreach (var notification in notificationManager.Notifications)
    {
        Console.WriteLine(notification.Message);
    }
}
Localized Notifications in ASP.NET Core

Create a dummy class to be used as a type argument for the factory.Create method:

public abstract class SharedResource;

Create your resource files in the Resources folder:

Resources/
    SharedResource.cs
    SharedResource.en-US.resx
    SharedResource.pt-BR.resx

Configure services in your Program.cs or Startup.cs:

using Microsoft.AspNetCore.Localization;
using Sozo.Toolkit.Notifications;
using System.Globalization;

builder.Services.AddLocalizedNotifications<SharedResource>(options =>
{
    options.DefaultRequestCulture = new RequestCulture("pt-BR");
    options.SupportedCultures = [new CultureInfo("pt-BR"), new CultureInfo("en-US")];
});

var app = builder.Build();
app.UseLocalizedNotifications();

Using the localized notification manager in your application:

public class MyService(LocalizedNotificationManager notificationManager)
{
    public void Execute()
    {
        // 'UserNotFound' should be a key defined in your resource files.
        _notificationManager.AddNotification("UserNotFound", "john doe");

        // Access notifications
        foreach (var notification in _notificationManager.Notifications)
        {
            Console.WriteLine($"{notification.Id}: {notification.Message} at {notification.Timestamp}");
        }
    }
}

4. Validators

using Sozo.Toolkit.Validators;

// Check if a string contains only allowed characters
bool isValid = CharsValidator.HasOnlyAllowedChars("abc", 'a', 'b', 'c'); // Returns: true

// Validate if a string has only digits
bool onlyDigits = CharsValidator.HasOnlyDigits("123456"); // Returns: true

// Validate email addresses
bool validEmail = EmailValidator.IsEmailAddress("test@example.com"); // Returns: true


Enjoy coding with Sozo.Toolkit! ✨

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta.20250326233608 143 3/26/2025