/**
 * Cleans the type text to rename any non-JS primitive or non-String/Number types with an 'I' prefix.
 */
export function cleanType(typeText: string): string {
  const jsPrimitives = [
    "string",
    "number",
    "boolean",
    "null",
    "undefined",
    "void",
    "date",
    "any",
  ];

  if (
    jsPrimitives.includes(typeText.toLowerCase()) ||
    (typeText.endsWith("[]") &&
      jsPrimitives.includes(typeText.replace("[]", "").toLowerCase()))
  ) {
    return typeText;
  }

  if (typeText.startsWith("Array<")) {
    return typeText.replace("Array<", "I").replace(">", "");
  }

  if (typeText.startsWith("{")) {
    return typeText;
  }

  if (typeText && !typeText.startsWith("I")) {
    return `I${typeText}`;
  }

  return typeText;
}
