toUserName static method

String toUserName(
  1. String name, {
  2. List<String>? regexList,
  3. List<String>? replacements,
})

Converts a username by applying regex and replacements.

Example: ('John Doe', regexList: ' ', replacements: '_') -> 'john_doe'

Implementation

static String toUserName(
  String name, {
  List<String>? regexList,
  List<String>? replacements,
}) {
  final String current = Replacement.auto(name).toLowerCase();
  if (replacements != null) {
    return Replacement.multiple(current, replacements, regexList ?? []);
  } else {
    return Replacement.single(current, "", regexList);
  }
}