toCamelCase property

String get toCamelCase

Converts a string to camelCase.

Example: 'hello world' becomes 'helloWorld' Converts a string to camelCase.

Example: 'hello world' becomes 'helloWorld'

Implementation

/// Converts a string to camelCase.
///
/// Example: 'hello world' becomes 'helloWorld'
String get toCamelCase {
  if (isEmpty) return '';
  final words = trim().split(RegExp(r'[\s_-]+'));
  final firstWord = words[0].toLowerCase();
  final remainingWords = words.skip(1).map((word) => word.isNotEmpty
      ? word[0].toUpperCase() + word.substring(1).toLowerCase()
      : '');
  return firstWord + remainingWords.join('');
}