transformIdentifierCaseStyle function

String transformIdentifierCaseStyle(
  1. String source,
  2. CaseStyle? targetCaseStyle,
  3. CaseStyle? sourceCaseStyle
)

Transforms identifier from sourceCaseStyle to targetCaseStyle

Implementation

String transformIdentifierCaseStyle(
    String source, CaseStyle? targetCaseStyle, CaseStyle? sourceCaseStyle) {
  if (sourceCaseStyle == targetCaseStyle) {
    return source;
  }
  switch (targetCaseStyle) {
    case CaseStyle.kebab:
      return toWords(source, sourceCaseStyle).join('-');
    case CaseStyle.snake:
      return toWords(source, sourceCaseStyle).join('_');
    case CaseStyle.snakeAllCaps:
      return toWords(source, sourceCaseStyle).join('_').toUpperCase();
    case CaseStyle.pascal:
      return toWords(source, sourceCaseStyle)
          .map((word) => capitalize(word))
          .join('');
    case CaseStyle.camel:
      return deCapitalize(toWords(source, sourceCaseStyle)
          .map((word) => word.toLowerCase())
          .map((e) => capitalize(e))
          .join(''));
    default:
      return source;
  }
}