extractCustomComponentValue function presentation exported

Last updated: 2026-03-04T23:21:38.378Z

Metrics

LOC: 38 Complexity: 13 Params: 1

Signature

extractCustomComponentValue(field: FormField): : string | null

Summary

Attempts to extract a string value from a custom component field. Returns null if the adapter does not provide an extractor or if extraction failed.

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'extractCustomComponentValue' has cyclomatic complexity 13 (max 10)

Source Code

export function extractCustomComponentValue(field: FormField): string | null {
  const adapterName = field.adapterName as AdapterName | undefined;
  if (!adapterName) return null;

  const adapter = getAdapter(adapterName);
  if (!adapter) return null;

  // Try adapter-provided extractor first
  if (typeof adapter.extractValue === "function") {
    try {
      const result = adapter.extractValue(field.element as HTMLElement);
      if (result !== null && result !== undefined) return result;
    } catch (err) {
      log.warn(
        `[${adapter.name}] Erro ao extrair valor do campo ${field.selector}:`,
        err,
      );
      // fallthrough to generic fallback
    }
  }

  // Generic fallback: look for a native input/select/textarea inside the wrapper.
  const native = field.element.querySelector<
    HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
  >("input,textarea,select");
  if (native) {
    if (native instanceof HTMLSelectElement) return native.value;
    if (native instanceof HTMLInputElement) {
      if (native.type === "checkbox" || native.type === "radio") {
        return native.checked ? "true" : "false";
      }
      return native.value;
    }
    return native.value;
  }

  return null;
}

Dependencies (Outgoing)

graph LR extractCustomComponentValue["extractCustomComponentValue"] getAdapter["getAdapter"] extractCustomComponentValue -->|calls| getAdapter style extractCustomComponentValue fill:#dbeafe,stroke:#2563eb,stroke-width:2px click extractCustomComponentValue "e6339fe1023108e6.html" click getAdapter "fb0f4a5fd9ac2a4b.html"
TargetType
getAdapter calls

Impact (Incoming)

graph LR extractCustomComponentValue["extractCustomComponentValue"] setNativeValue["setNativeValue"] captureFormValues["captureFormValues"] setNativeValue -->|uses| extractCustomComponentValue captureFormValues -->|calls| extractCustomComponentValue style extractCustomComponentValue fill:#dbeafe,stroke:#2563eb,stroke-width:2px click extractCustomComponentValue "e6339fe1023108e6.html" click setNativeValue "334bd99609d7c37c.html" click captureFormValues "6a3156502a77636f.html"
SourceType
setNativeValue uses
captureFormValues calls