capitalizeEachWord method

String capitalizeEachWord()

Implementation

String capitalizeEachWord() {
  if (length <= 1) {
    return toUpperCase();
  }
  final words = split(' ');
  final capitalized = words.map((final word) {
    final first = word.substring(0, 1).toUpperCase();
    final rest = word.substring(1);

    return '$first$rest';
  });

  return capitalized.join(' ');
}