mask method
Masks this string, keeping keepFirst characters at the start and
keepLast at the end, replacing the rest with maskChar.
Useful for credit cards, phone numbers, etc.
'4111111111111111'.mask(keepFirst: 4, keepLast: 4) // '4111********1111'
Implementation
String mask({int keepFirst = 0, int keepLast = 4, String maskChar = '*'}) {
if (length <= keepFirst + keepLast) return this;
final start = substring(0, keepFirst);
final end = substring(length - keepLast);
final masked = maskChar * (length - keepFirst - keepLast);
return '$start$masked$end';
}