Xreeple.Bukalemun.Masking 1.0.0-alpha.2508.5

This is a prerelease version of Xreeple.Bukalemun.Masking.
dotnet add package Xreeple.Bukalemun.Masking --version 1.0.0-alpha.2508.5
                    
NuGet\Install-Package Xreeple.Bukalemun.Masking -Version 1.0.0-alpha.2508.5
                    
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="Xreeple.Bukalemun.Masking" Version="1.0.0-alpha.2508.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xreeple.Bukalemun.Masking" Version="1.0.0-alpha.2508.5" />
                    
Directory.Packages.props
<PackageReference Include="Xreeple.Bukalemun.Masking" />
                    
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 Xreeple.Bukalemun.Masking --version 1.0.0-alpha.2508.5
                    
#r "nuget: Xreeple.Bukalemun.Masking, 1.0.0-alpha.2508.5"
                    
#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 Xreeple.Bukalemun.Masking@1.0.0-alpha.2508.5
                    
#: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=Xreeple.Bukalemun.Masking&version=1.0.0-alpha.2508.5&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Xreeple.Bukalemun.Masking&version=1.0.0-alpha.2508.5&prerelease
                    
Install as a Cake Tool

Xreeple.Bukalemun.Masking

A flexible and extensible string masking library for C#.
Supports different masking scenarios, customizable rules, and advanced options like compact masking or removing masked characters entirely.


📦 Installation

Install via NuGet:

dotnet add package Xreeple.Bukalemun.Masking

🚀 Usage

using System;
using Xreeple.Bukalemun.Masking;

class Program
{
    static void Main()
    {
        Console.WriteLine(Mask.Build("helloworld").RevealLast(3).ToString()); 
        // *******rld
    }
}

⚙️ API and Methods

All methods are chainable.


General Settings

  • MaskChar(char c)
    Changes the mask character.

    Mask.Build("mehmet").RevealLast(2).MaskChar('#').ToString(); 
    // ######et
    
  • CompactMask(int length)
    Replaces any hidden section with a compact block of the specified mask length.

    Mask.Build("mehmet").RevealFirst(2).CompactMask(3).ToString(); 
    // me***
    
  • RemoveMasked(bool remove = true)
    Removes masked characters completely instead of replacing them.

    Mask.Build("mehmet").RevealLast(3).RemoveMasked().ToString(); 
    // met
    

Masking Rules

  • RevealFirst(int count)
    Reveals the first count characters.

    Mask.Build("helloworld").RevealFirst(2).ToString(); 
    // he********
    
  • RevealLast(int count)
    Reveals the last count characters.

    Mask.Build("helloworld").RevealLast(3).ToString(); 
    // *******rld
    
  • RevealRange(int start, int length)
    Reveals characters in the given range.

    Mask.Build("helloworld").RevealRange(2, 4).ToString(); 
    // **llow*****
    
  • RevealInitialsPerWord()
    Reveals only the first letter of each word.

    Mask.Build("mehmet emin eker").RevealInitialsPerWord().ToString(); 
    // m***** e*** e***
    
  • RevealIf(Func<char, int, bool> predicate)
    Reveals characters that match a given condition.
    Example: reveal only digits.

    Mask.Build("abc123xyz").RevealIf((ch, i) => char.IsDigit(ch)).ToString();
    // ***123***
    

Special Rules

  • PreserveChars(params char[] chars)
    Ensures the given characters are always preserved (never masked).
    Mask.Build("555-123-4567").RevealLast(2).PreserveChars('-').ToString(); 
    // ***-***-**67
    

🧩 Combination Examples

// Initials per word + compact mask
Console.WriteLine(
    Mask.Build("mehmet emin eker")
        .RevealInitialsPerWord()
        .CompactMask(3)
        .ToString()
);
// m*** e*** e***


// Removing masked characters instead of replacing
Console.WriteLine(
    Mask.Build("mehmet")
        .RevealLast(2)
        .RemoveMasked()
        .ToString()
);
// et


// Range reveal + preserved characters
Console.WriteLine(
    Mask.Build("TR-2025-ABC")
        .RevealRange(3, 4)
        .PreserveChars('-')
        .ToString()
);
// **-2025-***


// Change mask character + reveal first letters
Console.WriteLine(
    Mask.Build("hello world")
        .RevealInitialsPerWord()
        .MaskChar('#')
        .CompactMask(2)
        .ToString()
);
// h## w##


// Conditional reveal (digits only)
Console.WriteLine(
    Mask.Build("user123data456")
        .RevealIf((ch, i) => char.IsDigit(ch))
        .CompactMask(3)
        .ToString()
);
// u***123***456

📄 License

MIT

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.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Initial release.