convert method

Map<String, dynamic> convert({
  1. required Map<String, dynamic> source,
})

Implementation

Map<String, dynamic> convert({
  required Map<String, dynamic> source,
}) {
  final destination = <String, dynamic>{};

  // go through key key in the map and convert based on the name (remap) and
  // the conversion (type)
  for (final key in map.keys) {
    final format = map[key];
    if (source.containsKey(key)) {
      final value = valueForKey(key, source);
      setValue(
        destination,
        format?.name ?? key,
        format?.convert != null ? format?.convert?.call(value) : value,
      );
    }
  }

  //* is a special case convert all keys not listed
  if (map.keys.contains('*')) {
    for (final key in source.keys) {
      if (!map.keys.contains(key)) {
        final format = map['*'];
        final value = valueForKey(key, source);
        setValue(
          destination,
          key,
          format?.convert != null ? format?.convert?.call(value) : value,
        );
      }
    }
  }
  return destination;
}