detectBasicType function exported ✓ 100.0%

Last updated: 2026-03-01T23:25:47.099Z

Metrics

LOC: 26 Complexity: 14 Params: 2 Coverage: 100.0% (18/18 lines, 40x executed)

Signature

detectBasicType( element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, ): : BasicTypeResult

Summary

Maps an HTML form element's native type to a FieldType. Returns "unknown" for ambiguous types like plain text or textarea.

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'detectBasicType' has cyclomatic complexity 14 (max 10)

Tags

#@param element - The native form control element#@returns A `BasicTypeResult` with type and detection method

Source Code

export function detectBasicType(
  element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,
): BasicTypeResult {
  if (element instanceof HTMLSelectElement)
    return { type: "select", method: "html-type" };

  if (element instanceof HTMLTextAreaElement)
    return { type: "unknown", method: "html-type" };

  const type = element.type?.toLowerCase();

  if (type === "checkbox") return { type: "checkbox", method: "html-type" };
  if (type === "radio") return { type: "radio", method: "html-type" };
  if (type === "email") return { type: "email", method: "html-type" };
  if (type === "tel") return { type: "phone", method: "html-type" };
  if (type === "password") return { type: "password", method: "html-type" };
  if (type === "number") return { type: "number", method: "html-type" };
  if (type === "date") return { type: "date", method: "html-type" };
  if (["time", "datetime-local", "month", "week"].includes(type))
    return { type: "date", method: "html-type" };
  if (type === "url") return { type: "website", method: "html-type" };
  if (type === "search") return { type: "text", method: "html-type" };
  if (type === "range") return { type: "number", method: "html-type" };

  return { type: "unknown", method: "html-type" };
}

No outgoing dependencies.

Impact (Incoming)

graph LR detectBasicType["detectBasicType"] handleRuleButtonClick["handleRuleButtonClick"] detectSuggestedType["detectSuggestedType"] makeInput["makeInput"] detect["detect"] makeField["makeField"] handleRuleButtonClick -->|uses| detectBasicType detectSuggestedType -->|calls| detectBasicType makeInput -->|uses| detectBasicType detect -->|uses| detectBasicType makeField -->|uses| detectBasicType style detectBasicType fill:#dbeafe,stroke:#2563eb,stroke-width:2px click detectBasicType "f8d5479646b82aad.html" click handleRuleButtonClick "302ac6e6209ebb8e.html" click detectSuggestedType "f6cfcac9fed800c4.html" click makeInput "4a0ab4c48290e654.html" click detect "ed8c392b11421792.html" click makeField "cf669300b39c144e.html"
SourceType
handleRuleButtonClick uses
detectSuggestedType calls
makeInput uses
detect uses
makeField uses