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
- [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)
| Source | Type |
|---|---|
| handleRuleButtonClick | uses |
| detectSuggestedType | calls |
| makeInput | uses |
| detect | uses |
| makeField | uses |