isValueValidForElement function ✓ 91.7%

Last updated: 2026-02-24T21:07:57.586Z

Metrics

LOC: 40 Complexity: 11 Params: 3 Coverage: 91.7% (11/12 lines, 24x executed)

Signature

isValueValidForElement( element: ValueConstraints["element"], value: string, ): : boolean

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'isValueValidForElement' has cyclomatic complexity 11 (max 10)

Source Code

function isValueValidForElement(
  element: ValueConstraints["element"],
  value: string,
): boolean {
  if (!element) return true;

  // Custom component wrappers (div, span, etc.) are not native form elements.
  // Skip the validity probe and trust the adapter to accept any generated value.
  if (
    !(element instanceof HTMLInputElement) &&
    !(element instanceof HTMLTextAreaElement) &&
    !(element instanceof HTMLSelectElement)
  ) {
    return true;
  }

  if (element instanceof HTMLSelectElement) {
    return true;
  }

  if (
    element instanceof HTMLInputElement &&
    (element.type === "checkbox" ||
      element.type === "radio" ||
      element.type === "file")
  ) {
    return true;
  }

  const probe = element.cloneNode(false) as
    | HTMLInputElement
    | HTMLTextAreaElement;

  try {
    probe.value = value;
    return probe.checkValidity();
  } catch {
    return false;
  }
}

No outgoing dependencies.

Impact (Incoming)

graph LR isValueValidForElement["isValueValidForElement"] adaptGeneratedValue["adaptGeneratedValue"] adaptGeneratedValue -->|calls| isValueValidForElement style isValueValidForElement fill:#dbeafe,stroke:#2563eb,stroke-width:2px click isValueValidForElement "5972465051ee2fe8.html" click adaptGeneratedValue "08c3ad8d1ea27c4d.html"
SourceType
adaptGeneratedValue calls