transformIdentifierCaseStyle function
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;
}
}