prepName static method

String prepName(
  1. String name, {
  2. dynamic firstUpper = false,
})

create a JSON/Dart compatible version of the attribute found this will use camelCase and split if it finds an _ in the json attribute name i.e. age converts to age but age_now converts to ageNow this is to provide consistency when generating the object models name the original attribute name to convert

Implementation

static String prepName(String name, {firstUpper = false}) {
  int pos = name.indexOf("_");
  if (pos == -1) {
    return (firstUpper) ? ConversionUtils.upperCaseFirst(name) : name;
  }
  List<String> components = name.split("_");
  late String result;
  components.asMap().forEach((key, value) {
    if (key == 0) {
      result = (firstUpper) ? ConversionUtils.upperCaseFirst(value) : value;
    } else {
      result += ConversionUtils.upperCaseFirst(value);
    }
  });
  return result;
}