MCPcopy
hub / github.com/github/awesome-copilot / normalizeState

Function normalizeState

extensions/site-studio/extension.mjs:578–597  ·  view source on GitHub ↗
(raw)

Source from the content-addressed store, hash-verified

576}
577
578function normalizeState(raw) {
579 if (!raw || typeof raw !== "object") {
580 return createInitialState();
581 }
582 const fallback = createInitialState();
583 const templatePackId = safeString(raw.templatePackId, fallback.templatePackId);
584 const normalizedTemplatePackId = TEMPLATE_PACKS[templatePackId] ? templatePackId : fallback.templatePackId;
585 return {
586 sections: Array.isArray(raw.sections) ? raw.sections : fallback.sections,
587 templatePackId: normalizedTemplatePackId,
588 fieldSuggestions: raw.fieldSuggestions && typeof raw.fieldSuggestions === "object" ? raw.fieldSuggestions : fallback.fieldSuggestions,
589 sectionSchemas: raw.sectionSchemas && typeof raw.sectionSchemas === "object" ? raw.sectionSchemas : fallback.sectionSchemas,
590 changeLog: Array.isArray(raw.changeLog) ? raw.changeLog : [],
591 contentProposals: Array.isArray(raw.contentProposals) ? raw.contentProposals : [],
592 milestones: Array.isArray(raw.milestones) ? raw.milestones : [],
593 theme: raw.theme && typeof raw.theme === "object" ? raw.theme : fallback.theme,
594 branch: safeString(raw.branch, fallback.branch),
595 lastUpdated: safeString(raw.lastUpdated, fallback.lastUpdated),
596 };
597}
598
599async function loadState() {
600 if (stateLoaded) {

Callers 1

loadStateFunction · 0.70

Calls 2

createInitialStateFunction · 0.85
safeStringFunction · 0.85

Tested by

no test coverage detected