adaptGeneratedValue function exported ✓ 100.0%
Last updated: 2026-02-24T21:07:57.586Z
Location
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)
| Target | Type |
|---|---|
| resolveMaxLength | calls |
| buildValueCandidates | calls |
| isValueValidForElement | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| generateWithConstraints | calls |
| generateDateForField | uses |