UNPKG

@intlayer/core

Version:

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

37 lines (35 loc) 1.32 kB
import * as NodeTypes from "@intlayer/types/nodeType"; //#region src/dictionaryManipulator/updateNodeChildren.ts 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 === NodeTypes.TRANSLATION || typedNode.nodeType === NodeTypes.ENUMERATION || typedNode.nodeType === NodeTypes.PLURAL || typedNode.nodeType === NodeTypes.CONDITION) { const newContent = Object.entries(content).reduce((acc, [key]) => { acc[key] = newChildren; return acc; }, {}); return { ...typedNode, [typedNode.nodeType]: newContent }; } if (typedNode.nodeType === NodeTypes.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 }), {}); }; //#endregion export { updateNodeChildren }; //# sourceMappingURL=updateNodeChildren.mjs.map