classifyField function exported ✓ 100.0%
Last updated: 2026-03-02T11:04:51.015Z
Metrics
LOC: 52
Complexity: 5
Params: 1
Coverage: 100.0% (18/18 lines, 5x executed)
Signature
classifyField(field: FormField): : FieldType
Summary
Classifies a FormField by building its signals string and running classifyByTfSoft. Falls back to HTML input[type] when the model is not confident enough.
Source Code
export function classifyField(field: FormField): FieldType {
const structured = structuredSignalsFromField(field);
const tfResult = classifyByTfSoft(structured.signals, structured.context);
const featureText = buildFeatureText(structured.signals, structured.context);
if (tfResult) {
log.groupCollapsed(
TF_MESSAGES.classify.groupLabel(
tfResult.type,
tfResult.score.toFixed(3),
field.selector,
),
);
log.debug(TF_MESSAGES.classify.featureText, featureText || "(none)");
log.debug(
TF_MESSAGES.classify.tfMatch(
tfResult.type,
tfResult.score.toFixed(3),
thresholds.model,
),
);
log.debug(TF_MESSAGES.classify.field, {
label: field.label,
name: field.name,
id: field.id,
placeholder: field.placeholder,
});
log.groupEnd();
return tfResult.type;
}
const inputType = (field.element as HTMLInputElement).type?.toLowerCase();
const htmlType: FieldType =
(TF_CONFIG.htmlTypeFallback[
inputType as keyof typeof TF_CONFIG.htmlTypeFallback
] as FieldType) ?? "unknown";
log.groupCollapsed(
TF_MESSAGES.classify.groupLabelFallback(htmlType, field.selector),
);
log.debug(TF_MESSAGES.classify.featureText, featureText || "(none)");
log.debug(TF_MESSAGES.classify.noMatch(inputType));
log.debug(TF_MESSAGES.classify.field, {
label: field.label,
name: field.name,
id: field.id,
placeholder: field.placeholder,
});
log.groupEnd();
return htmlType;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| classifyByTfSoft | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| handle | calls |
| generateWithTensorFlow | uses |
| buildKeywordsFromDictionary | uses |
| makeField | uses |
| resetModelMock | uses |