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

View all

  • [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)

graph LR detectSuggestedType["detectSuggestedType"] detectBasicType["detectBasicType"] detectSuggestedType -->|calls| detectBasicType style detectSuggestedType fill:#dbeafe,stroke:#2563eb,stroke-width:2px click detectSuggestedType "f6cfcac9fed800c4.html" click detectBasicType "f8d5479646b82aad.html"
TargetType
detectBasicType calls

Impact (Incoming)

graph LR detectSuggestedType["detectSuggestedType"] handleRuleButtonClick["handleRuleButtonClick"] handleRuleButtonClick -->|calls| detectSuggestedType style detectSuggestedType fill:#dbeafe,stroke:#2563eb,stroke-width:2px click detectSuggestedType "f6cfcac9fed800c4.html" click handleRuleButtonClick "302ac6e6209ebb8e.html"
SourceType
handleRuleButtonClick calls