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)

graph LR classifyField["classifyField"] classifyByTfSoft["classifyByTfSoft"] classifyField -->|calls| classifyByTfSoft style classifyField fill:#dbeafe,stroke:#2563eb,stroke-width:2px click classifyField "aa03a8b1140f5f42.html" click classifyByTfSoft "0bd31cb0fc7321e5.html"
TargetType
classifyByTfSoft calls

Impact (Incoming)

graph LR classifyField["classifyField"] handle["handle"] generateWithTensorFlow["generateWithTensorFlow"] buildKeywordsFromDictionary["buildKeywordsFromDictionary"] makeField["makeField"] resetModelMock["resetModelMock"] handle -->|calls| classifyField generateWithTensorFlow -->|uses| classifyField buildKeywordsFromDictionary -->|uses| classifyField makeField -->|uses| classifyField resetModelMock -->|uses| classifyField style classifyField fill:#dbeafe,stroke:#2563eb,stroke-width:2px click classifyField "aa03a8b1140f5f42.html" click handle "fd8235a9d9674da4.html" click generateWithTensorFlow "49e69a4b304badea.html" click buildKeywordsFromDictionary "dfb7d9bfef2aba38.html" click makeField "ae72134e0e8cd3e2.html" click resetModelMock "4ef72c19f1c89871.html"