get<T> method

T? get<T>(
  1. dynamic map,
  2. String path, {
  3. T converter(
    1. dynamic
    )?,
})

Gets the specified path's value.

USAGE:

DotMap.get(map, '1.2.3');

Implementation

T? get<T>(map, String path, {T Function(dynamic)? converter}) {
  List<String> keys = path.split('.');

  if (map[keys[0]] == null) {
    return null;
  }

  if (keys.length == 1) {
    return converter != null ? converter(map[keys[0]]) : map[keys[0]] as T;
  }

  return get(map[keys.removeAt(0)], keys.join('.'));
}