UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

55 lines 1.36 kB
import { NodeType } from "../types/index.mjs"; const updateNodeChildren = (section, newChildren) => { if (typeof section === "string") { return newChildren; } if (typeof section === "number") { return newChildren; } if (typeof section === "boolean") { return newChildren; } if (typeof section?.nodeType === "string") { const typedNode = section; const content = typedNode[typedNode.nodeType]; if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition) { const newContent = Object.entries(content).reduce( (acc, [key]) => ({ ...acc, [key]: newChildren }), {} ); return { ...typedNode, [typedNode.nodeType]: newContent }; } if (typedNode.nodeType === NodeType.Nested) { return typedNode; } return { ...typedNode, [typedNode.nodeType]: newChildren }; } if (!section || typeof section !== "object") { return newChildren; } if (Array.isArray(section)) { return section.map(() => newChildren); } return Object.entries( section ).reduce( (acc, [key]) => ({ ...acc, [key]: newChildren }), {} ); }; export { updateNodeChildren }; //# sourceMappingURL=updateNodeChildren.mjs.map