Mascarate 1.0.2

dotnet add package Mascarate --version 1.0.2                
NuGet\Install-Package Mascarate -Version 1.0.2                
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="Mascarate" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mascarate --version 1.0.2                
#r "nuget: Mascarate, 1.0.2"                
#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.
// Install Mascarate as a Cake Addin
#addin nuget:?package=Mascarate&version=1.0.2

// Install Mascarate as a Cake Tool
#tool nuget:?package=Mascarate&version=1.0.2                

🎭 Mascarate

Mascarate is a lightweight and easy-to-use library for formatting, validating, and removing masks in C# strings. Ideal for handling data such as CPF, CNPJ, phone numbers, ZIP codes, and much more. With Mascarate, you can apply and remove masks simply and efficiently, ensuring data consistency and validation in your applications.

🚀 Main Features

Apply Masks: Format strings with custom masks.

Remove Masks: Quickly and easily remove masks from strings.

Data Validation: Check if a string matches the specified mask.

Flexible Configuration: Define custom masks with special characters.

Lightweight and Efficient: Optimized for performance and low memory consumption.

📦 Installation

You can install Mascarate via NuGet:

dotnet add package Mascarate

Or through the NuGet Package Manager in Visual Studio:

Install-Package Mascarate

🛠 How to Use

1. Applying Masks

Use the Apply method to format a string with a mask:

using Mascarate.Extensions;

string cpf = "12345678901";
string maskedCpf = cpf.Mascarate("###.###.###-##"); // Result: "123.456.789-01"

2. Removing Masks

Use the Remove method to remove masks from a string:

using Mascarate.Extensions;

string maskedCpf = "123.456.789-01";
string unmaskedCpf = maskedCpf.UnMascarate(); // Result: "12345678901"

3. Validating Masks

Use the Validate method to check if a string matches the specified mask:

using Mascarate.Extensions;

string cpf = "123.456.789-01";
bool isValid = cpf.MascarateValidate("###.###.###-##"); // Result: true

4. Custom Masks

You can create custom masks using the following special characters:

  • #: Any numeric character ([0-9]).
  • @: Any alphabetic character ([A-Za-z]).
  • *: Any alphanumeric character ([A-Za-z0-9]).

Example:

using Mascarate.Extensions;

string phoneNumber = "11987654321";
string maskedPhone = phoneNumber.Mascarate("(##) #####-####"); // Result: "(11) 98765-4321"

📚 Practical Examples

CPF

string cpf = "12345678901";
string maskedCpf = cpf.Mascarate("###.###.###-##"); // "123.456.789-01"
string unmaskedCpf = maskedCpf.UnMascarate("###.###.###-##"); // "12345678901"
bool isValidCpf = maskedCpf.MascarateValidate("###.###.###-##"); // true

CNPJ

string cnpj = "12345678000199";
string maskedCnpj = cnpj.Mascarate("##.###.###/####-##"); // "12.345.678/0001-99"
string unmaskedCnpj = maskedCnpj.UnMascarate("##.###.###/####-##"); // "12345678000199"
bool isValidCnpj = maskedCnpj.MascarateValidate("##.###.###/####-##"); // true

Phone Number

string phoneNumber = "11987654321";
string maskedPhone = Mascarate.Mask.Apply(phoneNumber, "(##) #####-####"); // "(11) 98765-4321"
string unmaskedPhone = Mascarate.Mask.Remove(maskedPhone); // "11987654321"
bool isValidPhone = Mascarate.Mask.Validate(maskedPhone, "(##) #####-####"); // true

ZIP Code

string zipCode = "12345678";
string maskedZip = Mascarate.Mask.Apply(zipCode, "#####-###"); // "12345-678"
string unmaskedZip = Mascarate.Mask.Remove(maskedZip); // "12345678"
bool isValidZip = Mascarate.Mask.Validate(maskedZip, "#####-###"); // true

📜 Special Characters for Masks

  • #: Any number ([0-9]).
  • @: Any letter ([A-Za-z]).
  • *: Any alphanumeric character ([A-Za-z0-9]).

🤝 Contributing

Contributions are welcome! If you want to contribute to Mascarate, follow these steps:

  1. Fork the repository.

  2. Create a branch with your feature or fix:

    git checkout -b my-feature
    
  3. Commit your changes:

    git commit -m "My new feature"
    
  4. Push to the remote repository:

    git push origin my-feature
    
  5. Open a pull request on GitHub.

📄 License

This project is licensed under the MIT License. See the LICENSE file for more details.

🙏 Acknowledgments

Thank you for using Mascarate! If you enjoyed the project, leave a ⭐ on the repository and share it with other developers.

Product 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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • 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.

Version Downloads Last updated
1.0.2 73 2/5/2025
1.0.1 63 2/5/2025
1.0.0 73 2/4/2025