transformFieldName function

String transformFieldName (
  1. String input,
  2. CaseStyle caseStyle
)

Implementation

String transformFieldName(String input, CaseStyle caseStyle) {
  switch (caseStyle) {
    case CaseStyle.Kebab:
      return toWords(input).replaceAll(' ', '-');
    case CaseStyle.Snake:
      return toWords(input).replaceAll(' ', '_');
    case CaseStyle.SnakeAllCaps:
      return toWords(input).replaceAll(' ', '_').toUpperCase();
    case CaseStyle.Pascal:
      return toWords(input).split(' ').map((word) => capitalize(word)).join();
    default:
      return input;
  }
}