redactApiKey function

String redactApiKey(
  1. String key
)

Redact an API key, showing only the first and last few characters.

Implementation

String redactApiKey(String key) {
  if (key.length <= 8) return '*' * key.length;
  final showChars = (key.length > 20) ? 4 : 2;
  return '${key.substring(0, showChars)}${'*' * (key.length - showChars * 2)}${key.substring(key.length - showChars)}';
}