shape static method

String shape(
  1. String line, [
  2. int maxLength = 60
])

Masks a chat line so its format can be logged without its content: letters become a, digits become 9, and the line is truncated. e.g. [25/04/2022, 10:17:07] Dolev: Hi -> [99/99/9999, 99:99:99] aaaaa: aa

Implementation

static String shape(String line, [int maxLength = 60]) {
  final masked = line
      .replaceAll(RegExp(r'\p{L}', unicode: true), 'a')
      .replaceAll(RegExp(r'\p{N}', unicode: true), '9');
  return masked.length <= maxLength
      ? masked
      : '${masked.substring(0, maxLength)}…';
}