adaptGeneratedValue function exported ✓ 100.0%

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

Metrics

LOC: 15 Complexity: 5 Params: 3 Coverage: 100.0% (6/6 lines, 17x executed)

Signature

adaptGeneratedValue( value: string, constraints: ValueConstraints = {}, ): : string

Summary

Adapts a generated string value to fit within element constraints. Tries the original value, trimmed, collapsed-whitespace, and digits-only variants.

Tags

#@param value - Raw generated value#@param constraints - Optional element/length constraints#@returns The first variant that satisfies constraints, or empty string

Source Code

export function adaptGeneratedValue(
  value: string,
  constraints: ValueConstraints = {},
): string {
  const maxLength = resolveMaxLength(constraints);
  const candidates = buildValueCandidates(value, maxLength);

  for (const candidate of candidates) {
    if (isValueValidForElement(constraints.element, candidate)) {
      return candidate;
    }
  }

  return constraints.requireValidity ? "" : (candidates[0] ?? "");
}

Dependencies (Outgoing)

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

Impact (Incoming)

graph LR adaptGeneratedValue["adaptGeneratedValue"] generateWithConstraints["generateWithConstraints"] generateDateForField["generateDateForField"] generateWithConstraints -->|calls| adaptGeneratedValue generateDateForField -->|uses| adaptGeneratedValue style adaptGeneratedValue fill:#dbeafe,stroke:#2563eb,stroke-width:2px click adaptGeneratedValue "08c3ad8d1ea27c4d.html" click generateWithConstraints "b5634e31dcca6c7f.html" click generateDateForField "a214011e5ced5989.html"