toCase method

String toCase(
  1. KeyCase? keyCase
)

transforms the string to the specified case if case is null, then no transformation will be applied

Implementation

String toCase(KeyCase? keyCase) {
  switch (keyCase) {
    case KeyCase.camel:
      return _getWords(this)
          .mapIndexed((index, word) =>
              index == 0 ? word.toLowerCase() : word.capitalize())
          .join('');
    case KeyCase.pascal:
      return _getWords(this).map((word) => word.capitalize()).join('');
    case KeyCase.snake:
      return _getWords(this).map((word) => word.toLowerCase()).join('_');
    case null:
      return this;
    default:
      print('Unknown key case: $keyCase');
      return this;
  }
}