parseResponse method ✓ 92.3%
Last updated: 2026-03-01T23:25:47.068Z
Metrics
LOC: 35
Complexity: 10
Params: 1
Coverage: 92.3% (12/13 lines, 17x executed)
Signature
parseResponse(raw: string): : FieldClassifierOutput | null
Source Code
parseResponse(raw: string): FieldClassifierOutput | null {
try {
const match = raw.match(/\{[^{}]+\}/);
if (!match) return null;
const parsed = JSON.parse(match[0]) as Record<string, unknown>;
if (
typeof parsed.fieldType !== "string" ||
!VALID_FIELD_TYPES.has(parsed.fieldType) ||
typeof parsed.confidence !== "number"
) {
return null;
}
const fieldType = parsed.fieldType as FieldType;
const confidence = Math.max(0, Math.min(1, parsed.confidence));
// Discard low-confidence and "unknown" results
if (fieldType === "unknown" || confidence < CLASSIFIER_MIN_CONFIDENCE) {
return null;
}
// generatorType — must be a valid FieldType; falls back to fieldType
const generatorType =
typeof parsed.generatorType === "string" &&
VALID_FIELD_TYPES.has(parsed.generatorType)
? (parsed.generatorType as FieldType)
: fieldType;
return { fieldType, confidence, generatorType };
} catch {
return null;
}
},
No outgoing dependencies.
No incoming dependencies.