validatedName static method

String? validatedName(
  1. String? name, {
  2. required bool reserveName,
})

Returns name if it meets requirements for the specified reserveName, otherwise throws an Exception.

This same function is reusable for other reference names like Modules, not only Logics.

Implementation

static String? validatedName(String? name, {required bool reserveName}) {
  if (reserveName) {
    if (name == null) {
      throw NullReservedNameException();
    } else if (name.isEmpty) {
      throw EmptyReservedNameException();
    } else if (!Sanitizer.isSanitary(name)) {
      throw InvalidReservedNameException();
    }
  }

  return name;
}