toCamelCase method

String toCamelCase()

Implementation

String toCamelCase() {
  if (isEmpty) return this;

  // Split by underscore, filter out empty parts, and convert to camel case
  final parts = split('_').where((part) => part.isNotEmpty).toList();

  if (parts.isEmpty) return '';

  // Convert first part to lowercase, others to title case
  return parts
      .asMap()
      .entries
      .map((entry) {
        final index = entry.key;
        final word = entry.value;
        if (word.isEmpty) return '';
        return index == 0
            ? word.toLowerCase()
            : word[0].toUpperCase() + word.substring(1).toLowerCase();
      })
      .join('');
}