scai
Version:
> **AI-powered CLI for local code analysis, commit message suggestions, and natural-language queries.** 100% local, private, GDPR-friendly, made in Denmark/EU with ❤️.
24 lines (23 loc) • 744 B
JavaScript
/**
* normalizeData ensures that ModuleIO.data is always returned as a usable object.
*
* Modules may output either a JSON string or a structured object. This helper
* converts JSON strings into objects, passes objects through unchanged, and
* provides a safe fallback for null/undefined. It centralizes the parsing logic
* so individual modules don’t need to guess the data format.
*/
export function normalizeData(data) {
if (data == null)
return {};
if (typeof data === "object")
return data;
if (typeof data === "string") {
try {
return JSON.parse(data);
}
catch {
throw new Error("Invalid JSON string in ModuleIO.data");
}
}
return {};
}