MCPcopy Create free account
hub / github.com/OpenDCAI/Paper2Any / normalizeNode

Function normalizeNode

frontend-workflow/src/utils/mindmapTree.ts:43–65  ·  view source on GitHub ↗
(raw: unknown, prefix: string, depth = 0, maxDepth = 6)

Source from the content-addressed store, hash-verified

41};
42
43const normalizeNode = (raw: unknown, prefix: string, depth = 0, maxDepth = 6): MindMapTreeNode => {
44 if (!raw || typeof raw !== 'object') {
45 return { id: prefix, label: 'Topic', summary: '', children: [] };
46 }
47
48 const rawNode = raw as Record<string, unknown>;
49 const label = coerceText(rawNode.label ?? rawNode.title ?? rawNode.name, 'Topic');
50 const summary = coerceText(rawNode.summary ?? rawNode.note ?? rawNode.description, '');
51 const childrenInput = Array.isArray(rawNode.children) ? rawNode.children : [];
52 const children =
53 depth >= maxDepth
54 ? []
55 : childrenInput
56 .slice(0, 8)
57 .map((child, index) => normalizeNode(child, `${prefix}_${index + 1}`, depth + 1, maxDepth));
58
59 return {
60 id: coerceText(rawNode.id, prefix),
61 label,
62 summary,
63 children,
64 };
65};
66
67export const normalizeMindMapTree = (raw: unknown, maxDepth = 6): MindMapTreeNode => {
68 const root = normalizeNode(raw, 'root', 0, maxDepth);

Callers 1

normalizeMindMapTreeFunction · 0.85

Calls 2

coerceTextFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected