buildValueCandidates function presentation ✓ 100.0%

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

Metrics

LOC: 35 Complexity: 12 Params: 2 Coverage: 100.0% (19/19 lines, 17x executed)

Signature

buildValueCandidates(value: string, maxLength: number): : string[]

Architecture violations

View all

  • [warning] max-cyclomatic-complexity: 'buildValueCandidates' has cyclomatic complexity 12 (max 10)

Source Code

function buildValueCandidates(value: string, maxLength: number): string[] {
  const candidates: string[] = [];

  const pushCandidate = (candidate: string): void => {
    if (!candidate && candidate !== "") return;
    if (!candidates.includes(candidate)) {
      candidates.push(candidate);
    }
  };

  pushCandidate(value);

  const trimmed = value.trim();
  if (trimmed !== value) pushCandidate(trimmed);

  const collapsedWhitespace = value.replace(/\s+/g, " ").trim();
  if (collapsedWhitespace && collapsedWhitespace !== value) {
    pushCandidate(collapsedWhitespace);
  }

  const digitsOnly = value.replace(/\D+/g, "");
  if (digitsOnly && digitsOnly !== value) {
    pushCandidate(digitsOnly);
  }

  if (maxLength > 0) {
    for (const candidate of [...candidates]) {
      if (candidate.length > maxLength) {
        pushCandidate(candidate.slice(0, maxLength));
      }
    }
  }

  return candidates;
}

No outgoing dependencies.

Impact (Incoming)

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