decode static method

Map<String, dynamic> decode(
  1. dynamic input, [
  2. DecodeOptions options = const DecodeOptions()
])

Decodes a String or Map<String, dynamic> into a Map<String, dynamic>. Providing custom options will override the default behavior.

Implementation

static Map<String, dynamic> decode(
  dynamic input, [
  DecodeOptions options = const DecodeOptions(),
]) {
  if (!(input is String? || input is Map<String, dynamic>?)) {
    throw ArgumentError.value(
      input,
      'input',
      'The input must be a String or a Map<String, dynamic>',
    );
  }

  if (input?.isEmpty ?? true) {
    return <String, dynamic>{};
  }

  Map<String, dynamic>? tempObj = input is String
      ? _$Decode._parseQueryStringValues(input, options)
      : input;
  Map<String, dynamic> obj = {};

  // Iterate over the keys and setup the new object
  if (tempObj?.isNotEmpty ?? false) {
    for (final MapEntry<String, dynamic> entry in tempObj!.entries) {
      final newObj = _$Decode._parseKeys(
        entry.key,
        entry.value,
        options,
        input is String,
      );

      obj = Utils.merge(
        obj,
        newObj,
        options,
      );
    }
  }

  return Utils.compact(obj);
}