mask method

String mask({
  1. int start = 0,
  2. int end = -1,
  3. String maskChar = '*',
})

Mask part of the string (e.g., hiding email or phone digits).

Example:

'1234567890'.mask(start: 3, end: 7) → '123****890'

Implementation

String mask({int start = 0, int end = -1, String maskChar = '*'}) {
  if (isEmpty) return this;
  int e = end == -1 ? length : end;
  if (start >= e) return this;
  String masked = List.generate(e - start, (_) => maskChar).join();
  return substring(0, start) + masked + substring(e);
}