mask method

String? mask({
  1. int upto = 4,
  2. String mask = '*',
  3. bool atEnd = false,
})

Replaces all but the last num runes of a string with the specified mask.

Implementation

String? mask({int upto = 4, String mask = '*', bool atEnd = false}) {
  if (length <= 1 || upto < 1 || length < upto) {
    return this;
  }

  return atEnd
      ? substring(0, length - upto) + mask * upto
      : mask * upto + substring(upto);
}