export const replaceSpacesToEmptyLines = <T = unknown>(object: T): T => {
  if (Array.isArray(object)) {
    return object.map(replaceSpacesToEmptyLines) as T;
  }

  if (!object || typeof object !== "object") {
    return object;
  }

  const result: Record<string, unknown> = {};

  for (const [key, value] of Object.entries(object)) {
    if (typeof value === "string") {
      if (value === " ") {
        result[key] = value.replace(" ", "");

        continue;
      }

      result[key] = value.replace(/\" \"/g, '""');

      continue;
    }

    if (typeof value === "object") {
      result[key] = replaceSpacesToEmptyLines(value);

      continue;
    }

    result[key] = value;
  }

  return result as T;
};
