toCamelCase property
String
get
toCamelCase
Converts the string to camel case.
- This method splits the string by spaces, hyphens, or underscores and converts it into camel case, where the first word is lowercase and all subsequent words start with an uppercase letter.
- Returns a new string in camel case.
Example:
"hello world".toCamelCase; // Returns "helloWorld"
Returns: A String in camel case.
Implementation
String get toCamelCase {
List<String> words = split(RegExp(r'[\s_-]+'));
if (words.isEmpty) return this;
return words.first.toLowerCase() +
words.skip(1).map((word) {
if (word.isEmpty) return '';
return word[0].toUpperCase() + word.substring(1).toLowerCase();
}).join('');
}