toCamelCase method

String toCamelCase()

Converts a string to camelCase.

'hello_world'.toCamelCase() // 'helloWorld'
'Hello World'.toCamelCase() // 'helloWorld'

Implementation

String toCamelCase() {
  if (isEmpty) return '';
  final words = trim().split(RegExp(r'[\s_\-]+'));
  if (words.isEmpty) return '';
  return words.first.toLowerCase() +
      words.skip(1).map((w) => w.capitalize()).join();
}