toClassName static method

String toClassName(
  1. String name, {
  2. String? prefix,
  3. String? suffix,
})

Converts a string (typically a database table or column name) to a Dart class name convention (PascalCase or UpperCamelCase).

An optional prefix and/or suffix can be added to the generated class name.

Examples:

StringUtils.toClassName("user_profiles") // "UserProfiles"
StringUtils.toClassName("user_profiles", prefix: "Db") // "DbUserProfiles"
StringUtils.toClassName("categories", suffix: "Table") // "CategoriesTable"

Implementation

static String toClassName(String name, {String? prefix, String? suffix}) {
  final className = ReCase(name).pascalCase;
  return '${prefix ?? ''}$className${suffix ?? ''}';
}