Repository: Significant-Gravitas/Auto-GPT
File: autogpt_platform/frontend/src/lib/utils.ts (TypeScript)

Code before:
    if (!current[key] || typeof current[key] !== "object") {
      current[key] = {};
    }
    current = current[key];
  }

  current[keys[keys.length - 1]] = value;
}

export function removeEmptyStringsAndNulls(obj: any): any {
  if (Array.isArray(obj)) {
    // If obj is an array, recursively remove empty strings and nulls from its elements
    return obj
      .map((item) => removeEmptyStringsAndNulls(item))
      .filter(
        (item) =>
          item !== null && (typeof item !== "string" || item.trim() !== ""),
      );
  } else if (typeof obj === "object" && obj !== null) {
    // If obj is an object, recursively remove empty strings and nulls from its properties
    for (const key in obj) {
      if (obj.hasOwnProperty(key)) {
        const value = obj[key];
        if (
          value === null ||
          (typeof value === "string" && value.trim() === "")
        ) {
          delete obj[key];
        } else {
          obj[key] = removeEmptyStringsAndNulls(value);
        }
      }
    }
  }
  return obj;
}

export const categoryColorMap: Record<string, string> = {
  AI: "bg-orange-300/[.7]",
  SOCIAL: "bg-yellow-300/[.7]",
  TEXT: "bg-green-300/[.7]",
  SEARCH: "bg-blue-300/[.7]",
  BASIC: "bg-purple-300/[.7]",
  INPUT: "bg-cyan-300/[.7]",
  OUTPUT: "bg-red-300/[.7]",
  LOGIC: "bg-teal-300/[.7]",
};

export function getPrimaryCategoryColor(categories: Category[]): string {
  if (categories.length === 0) {
    return "bg-gray-300/[.7]";

Review comment (suggestion):
fun fact: `value === null || value === undefined` is the same as `value == null` but maybe keep it explicit as is

Code after:
    if (!current[key] || typeof current[key] !== "object") {
      current[key] = {};
    }
    current = current[key];
  }

  current[keys[keys.length - 1]] = value;
}

export function removeEmptyStringsAndNulls(obj: any): any {
  if (Array.isArray(obj)) {
    // If obj is an array, recursively check each element,
    // but element removal is avoided to prevent index changes.
    return obj.map((item) =>
      item === undefined || item === null
        ? ""
        : removeEmptyStringsAndNulls(item),
    );
  } else if (typeof obj === "object" && obj !== null) {
    // If obj is an object, recursively remove empty strings and nulls from its properties
    for (const key in obj) {
      if (obj.hasOwnProperty(key)) {
        const value = obj[key];
        if (
          value === null ||
          value === undefined ||
          (typeof value === "string" && value === "")
        ) {
          delete obj[key];
        } else {
          obj[key] = removeEmptyStringsAndNulls(value);
        }
      }
    }
  }
  return obj;
}

export const categoryColorMap: Record<string, string> = {
  AI: "bg-orange-300/[.7]",
  SOCIAL: "bg-yellow-300/[.7]",
  TEXT: "bg-green-300/[.7]",
  SEARCH: "bg-blue-300/[.7]",
  BASIC: "bg-purple-300/[.7]",
  INPUT: "bg-cyan-300/[.7]",
  OUTPUT: "bg-red-300/[.7]",
  LOGIC: "bg-teal-300/[.7]",
};

export function getPrimaryCategoryColor(categories: Category[]): string {
  if (categories.length === 0) {