pluralize method

String pluralize(
  1. num? count, {
  2. bool simple = false,
})

Returns the plural form of this string.

Implementation

String pluralize(num? count, {bool simple = false}) {
  if (isEmpty || count == 1 || length == 1) return this;
  if (simple) return '${this}s';

  final String lastChar = lastChars(1);
  switch (lastChar) {
    case 's':
    case 'x':
    case 'z':
      return '${this}es';
    case 'y':
      if (length > 2 && this[length - 2].isVowel()) return '${this}s';
      return '${substringSafe(0, length - 1)}ies';
  }

  final String lastTwo = lastChars(2);
  if (lastTwo == 'sh' || lastTwo == 'ch') return '${this}es';
  return '${this}s';
}