detectSuggestedType function
Last updated: 2026-03-04T23:21:38.396Z
Metrics
LOC: 36
Complexity: 13
Params: 1
Signature
detectSuggestedType(target: HTMLElement): : FieldType | undefined
Summary
Attempts a fast synchronous detection of the field type using HTML type attributes first, then keyword classifier as fallback.
Architecture violations
- [warning] max-cyclomatic-complexity: 'detectSuggestedType' has cyclomatic complexity 13 (max 10)
Source Code
function detectSuggestedType(target: HTMLElement): FieldType | undefined {
const el = target as
| HTMLInputElement
| HTMLSelectElement
| HTMLTextAreaElement;
const isFormEl =
el instanceof HTMLInputElement ||
el instanceof HTMLSelectElement ||
el instanceof HTMLTextAreaElement;
if (!isFormEl) return undefined;
const htmlResult = detectBasicType(el);
if (htmlResult.type !== "unknown" && htmlResult.type !== "text") {
return htmlResult.type;
}
const label = findLabel(target) || undefined;
const minimalField: Partial<FormField> = {
element: el,
name: (el as HTMLInputElement).name || undefined,
id: el.id || undefined,
placeholder:
("placeholder" in el
? (el as HTMLInputElement).placeholder
: undefined) || undefined,
label,
};
minimalField.contextSignals = buildSignals(minimalField as FormField);
const kwResult = keywordClassifier.detect(minimalField as FormField);
if (kwResult?.type && kwResult.type !== "unknown") {
return kwResult.type;
}
return undefined;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| detectBasicType | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handleRuleButtonClick | calls |