src/lib/form/detectors/strategies/html-type-classifier.ts

Total Symbols
1
Lines of Code
24
Avg Complexity
3.0
Avg Coverage
100.0%

Symbols by Kind

method 1

All Symbols

Name Kind Visibility Status Lines Signature
detect method - 14-22 detect(field): : ClassifierResult | null

Full Source

/**
 * HTML Type Classifier
 *
 * Maps input[type], <select> and <textarea> to a FieldType with 100% confidence.
 * Returns null for plain text inputs and textareas — subsequent classifiers handle them.
 */

import type { FieldClassifier, ClassifierResult } from "../pipeline";
import { detectBasicType } from "../html-type-detector";
import { isNativeFormElement } from "@/types";

export const htmlTypeClassifier: FieldClassifier = {
  name: "html-type",
  detect(field): ClassifierResult | null {
    const el = field.element;
    if (!isNativeFormElement(el as HTMLElement)) return null;
    const { type } = detectBasicType(
      el as HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement,
    );
    if (type === "unknown") return null;
    return { type, confidence: 1.0 };
  },
};