toCamelCase method

String toCamelCase()

Converts this string to camelCase

Example:

print('hello world'.toCamelCase()); // "helloWorld"
print('hello-world'.toCamelCase()); // "helloWorld"

Implementation

String toCamelCase() {
  if (isEmpty) return this;
  final words = split(RegExp(r'[\s\-_]+'));
  if (words.isEmpty) return this;

  final first = words.first.toLowerCase();
  final rest = words.skip(1).map((word) => word.capitalize()).join('');
  return first + rest;
}