resolveComponent static method

Map<String, String> resolveComponent({
  1. required String rawFeatureName,
  2. required String componentType,
  3. required String rawComponentName,
})

Resolves component (screen, model, repository) variable variants along with feature name variants.

Implementation

static Map<String, String> resolveComponent({
  required String rawFeatureName,
  required String componentType,
  required String rawComponentName,
}) {
  final featureVars = resolveFeature(rawFeatureName: rawFeatureName);

  final trimmedComp = rawComponentName.trim();
  if (trimmedComp.isEmpty) {
    throw ValidationException('$componentType name cannot be empty.');
  }

  final words = _extractWords(trimmedComp);
  if (words.isEmpty) {
    throw ValidationException(
        'Invalid $componentType name: "$rawComponentName"');
  }

  final snakeCase = words.map((w) => w.toLowerCase()).join('_');
  final pascalCase = words.map((w) => _capitalize(w)).join('');
  final camelCase = words.first.toLowerCase() +
      words.sublist(1).map((w) => _capitalize(w)).join('');

  final prefix = '${componentType.toLowerCase()}_name';

  return {
    ...featureVars,
    prefix: trimmedComp,
    '${prefix}_snake_case': snakeCase,
    '${prefix}_pascal_case': pascalCase,
    '${prefix}_camel_case': camelCase,
  };
}