namespace Galaeth.Core.Extensions;
///
/// Extension methods for strings.
///
public static class StringExtensions
{
///
/// Mask an email address for logging purposes.
///
/// The email address to obfuscate.
/// The obfuscated email address, or the original if there's an issue with the email address.
public static string MaskEmailAddress(this string emailAddress)
{
if (string.IsNullOrWhiteSpace(emailAddress))
{
return string.Empty;
}
if (!emailAddress.Contains('@'))
{
return emailAddress;
}
if (emailAddress.StartsWith('@'))
{
return emailAddress;
}
return $"{emailAddress[0]}****{emailAddress[(emailAddress.IndexOf('@') - 1) ..]}";
}
}