jsToDart function

Object? jsToDart(
  1. Object? o
)

Converts o to Dart primitives or collections.

o Can be any primitive value, a JsArray or a JsObject).

Implementation

Object? jsToDart(Object? o) {
  if (o == null) return null;

  if (o is String) return o;
  if (o is num) return o;
  if (o is bool) return o;

  if (o is JsArray) return jsArrayToList(o);
  if (o is JsObject) return jsObjectToMap(o);

  if (o is List) return o.map(jsToDart).toList();
  if (o is Map) {
    return o.map((key, value) => MapEntry(jsToDart(key), jsToDart(value)));
  }

  return o;
}