@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
37 lines (35 loc) • 1.26 kB
JavaScript
import { NodeType } from "@intlayer/types";
//#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 === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition) {
const newContent = Object.entries(content).reduce((acc, [key]) => {
acc[key] = newChildren;
return acc;
}, {});
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
}), {});
};
//#endregion
export { updateNodeChildren };
//# sourceMappingURL=updateNodeChildren.mjs.map