toCamelCase method

String toCamelCase()

Converts the string to camelCase (e.g., "hello world" -> "helloWorld").

Capitalizes the first letter of each word after the first and removes spaces.

Example:

"hello world".toCamelCase(); // Returns "helloWorld"
"snake_case".toCamelCase(); // Returns "snakeCase"

Implementation

String toCamelCase() {
  if (isEmpty) return this;
  final words = trim().split(RegExp(r'[\s_]+'));
  return words.first.toLowerCase() +
      words.skip(1).map((word) {
        if (word.isEmpty) return word;
        return word[0].toUpperCase() + word.substring(1).toLowerCase();
      }).join();
}