diff --git a/Readme.md b/Readme.md index a776632..3bd6b2b 100644 --- a/Readme.md +++ b/Readme.md @@ -201,6 +201,13 @@ string maskedEmail = Mask.MaskEmail("example@email.com"); string maskedPhone = Mask.MaskPhoneNumber("1234567890"); // Output: "******7890" + +// You can also use the MaskEmail and MaskPhoneNumber methods as extension methods on strings +string maskedEmail = "example@email.com"; +string maskedPhone = "1234567890"; + +string maskedEmail = maskedEmail.MaskEmail(); +string maskedPhone = maskedPhone.MaskPhoneNumber(); ``` ## 1.5. License diff --git a/src/Pandatech.Crypto.Tests/MaskTests.cs b/src/Pandatech.Crypto.Tests/MaskTests.cs index 75a9d08..0909d95 100644 --- a/src/Pandatech.Crypto.Tests/MaskTests.cs +++ b/src/Pandatech.Crypto.Tests/MaskTests.cs @@ -13,7 +13,7 @@ public class MaskTests [InlineData("a@b.com", "a@b.com")] public void MaskEmail_ValidEmails_ReturnsMaskedEmail(string input, string expected) { - var result = Mask.MaskEmail(input); + var result = input.MaskEmail(); Assert.Equal(expected, result); } @@ -22,7 +22,7 @@ public void MaskEmail_ValidEmails_ReturnsMaskedEmail(string input, string expect [InlineData("notanemail")] public void MaskEmail_InvalidEmails_ThrowsArgumentException(string input) { - Assert.Throws(() => Mask.MaskEmail(input)); + Assert.Throws(input.MaskEmail); } [Theory] @@ -31,7 +31,7 @@ public void MaskEmail_InvalidEmails_ThrowsArgumentException(string input) [InlineData("12", "12")] public void MaskPhoneNumber_ValidPhoneNumbers_ReturnsMaskedPhone(string input, string expected) { - var result = Mask.MaskPhoneNumber(input); + var result = input.MaskPhoneNumber(); Assert.Equal(expected, result); } @@ -40,6 +40,6 @@ public void MaskPhoneNumber_ValidPhoneNumbers_ReturnsMaskedPhone(string input, s [InlineData("")] public void MaskPhoneNumber_InvalidPhoneNumbers_ThrowsArgumentException(string input) { - Assert.Throws(() => Mask.MaskPhoneNumber(input)); + Assert.Throws(input.MaskPhoneNumber); } } \ No newline at end of file diff --git a/src/Pandatech.Crypto/Mask.cs b/src/Pandatech.Crypto/Mask.cs index f43a9d3..970a321 100644 --- a/src/Pandatech.Crypto/Mask.cs +++ b/src/Pandatech.Crypto/Mask.cs @@ -4,7 +4,7 @@ namespace Pandatech.Crypto; public static class Mask { - public static string MaskEmail(string email) + public static string MaskEmail(this string email) { if (!PandaValidator.IsEmail(email)) { @@ -20,7 +20,7 @@ public static string MaskEmail(string email) return $"{maskedLocalPart}@{domainPart}"; } - public static string MaskPhoneNumber(string phoneNumber) + public static string MaskPhoneNumber(this string phoneNumber) { if (string.IsNullOrEmpty(phoneNumber)) { diff --git a/src/Pandatech.Crypto/Pandatech.Crypto.csproj b/src/Pandatech.Crypto/Pandatech.Crypto.csproj index a107e89..4abb828 100644 --- a/src/Pandatech.Crypto/Pandatech.Crypto.csproj +++ b/src/Pandatech.Crypto/Pandatech.Crypto.csproj @@ -8,12 +8,12 @@ MIT pandatech.png Readme.md - 2.2.5 + 2.2.6 Pandatech.Crypto Pandatech, library, encryption, hash, algorythms, security PandaTech.Crypto is a .NET library simplifying common cryptograhic functions. https://github.com/PandaTechAM/be-lib-pandatech-crypto - Added Mask class + Mask class extension