scai
Version:
> **A local-first AI CLI for understanding, querying, and iterating on large codebases.** > **100% local • No token costs • No cloud • No prompt injection • Private by design**
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 {};
}