blur static method

String blur(
  1. String? value
)

模糊化字符串

根据字符串长度采用不同的模糊策略:

  • 长度 <= 4:直接返回 "***"
  • 长度 5~8:保留首字符和尾字符,中间用 "***" 替代
  • 长度 > 8:保留前三位和后两位,中间用 "***" 替代

Blur string based on length:

  • Length <= 4: Returns "***" directly
  • Length 5~8: Keeps first and last character, replaces middle with "***"
  • Length > 8: Keeps first 3 and last 2 characters, replaces middle with "***"

Implementation

static String blur(String? value) {
  if (value == null) return 'null';

  final len = value.length;
  if (len <= _minBlurLength) return _mask;
  if (len <= 8) return '${value[0]}$_mask${value[len - 1]}';
  return '${value.substring(0, 3)}$_mask${value.substring(len - 2)}';
}