cloneRecuriveMap method

Map cloneRecuriveMap({
  1. required Map data,
  2. required List<HideRegExp> hideRegExps,
  3. bool ignoreError = false,
})

Implementation

Map cloneRecuriveMap({
  required Map data,
  required List<HideRegExp> hideRegExps,
  bool ignoreError = false,
}) {
  Map newData = {};

  data.forEach((key, value) {
    for (var i = 0; i < hideRegExps.length; i++) {
      try {
        HideRegExp hideRegExp = hideRegExps[i];
        if (hideRegExp.regExp.hashData(key)) {
          if (value is Map) {
            newData[key] = cloneRecuriveMap(
                data: value,
                hideRegExps: hideRegExps,
                ignoreError: ignoreError);
          } else if (value is List) {
            newData[key] = cloneRecuriveList(
                data: value,
                hideRegExps: hideRegExps,
                ignoreError: ignoreError);
          } else if (value is String) {
            if (hideRegExp.hideDataType == HideDataType.replace) {
              newData[key] = hideRegExp.replace;
            }
            if (hideRegExp.hideDataType == HideDataType.obfuscate) {
              newData[key] = obfocustData(
                mystring: value,
                start: hideRegExp.startIndexObfuscate,
                end: hideRegExp.endIndexObfuscate,
              );
            }
          } else if (data is int) {
            newData[key] = int.parse(hideData(
                data: "${value}",
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is double) {
            newData[key] = double.parse(hideData(
                data: "${value}",
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is num) {
            newData[key] = num.parse(hideData(
                data: "${value}",
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is bool) {
            newData[key] = value;
          } else {
            newData[key] = value;
          }
        } else if (value is String) {
          if (hideRegExp.regExp.hashData(value)) {
            newData[key] = (hideData(
                data: value,
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else {
            newData[key] = value;
          }
        } else {
          if (value is Map) {
            newData[key] = cloneRecuriveMap(
                data: value,
                hideRegExps: hideRegExps,
                ignoreError: ignoreError);
          } else if (value is List) {
            newData[key] = cloneRecuriveList(
                data: value,
                hideRegExps: hideRegExps,
                ignoreError: ignoreError);
          } else if (value is String) {
            newData[key] = (hideData(
                data: value,
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is int) {
            newData[key] = int.parse(hideData(
                data: "${value}",
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is double) {
            newData[key] = double.parse(hideData(
                data: "${value}",
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is num) {
            newData[key] = num.parse(hideData(
                data: "${value}",
                hideRegExps: hideRegExps,
                ignoreError: ignoreError));
          } else if (data is bool) {
            newData[key] = value;
          } else {
            newData[key] = value;
          }
        }
      } catch (e) {
        if (ignoreError) {
          newData[key] = "error_parse_script_library";
        } else {
          rethrow;
        }
      }
    }
  });

  return newData;
}