obfuscate property
String
get
obfuscate
!~~~~~~~~~~~~~~~~~~~~~~~ Obfuscate ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Obfuscates a string by replacing the middle characters with asterisks.
If the string's length is less than or equal to 3, it returns the original string unchanged. Otherwise, it keeps the first three and last three characters and replaces the characters in between with asterisks.
Example:
"1234567890".obfuscate; // Returns "123*******0"
"abcdef".obfuscate; // Returns "abc***f"
"abc".obfuscate; // Returns "abc" (length <= 3)
"ab".obfuscate; // Returns "ab" (length <= 3)
"a".obfuscate; // Returns "a" (length <= 3)
"".obfuscate; // Returns "" (length <= 3)
Returns: The obfuscated string, or the original string if its length is less than or equal to 3.
Implementation
String get obfuscate {
if (length <= 3) return this;
String start = substring(0, 3);
String end = substring(length - 3);
String obfuscatedText = '$start${'*' * (length - 6)}$end';
return obfuscatedText;
}