UNPKG

@intlayer/core

Version:

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

47 lines 1.35 kB
import { NodeType } from "../types/index.mjs"; const getEmptyNode = (section) => { if (typeof section === "string") { return ""; } if (typeof section === "number") { return 0; } if (typeof section === "boolean") { return true; } 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 || typedNode.nodeType === NodeType.Insertion) { return getEmptyNode(content); } if (typedNode.nodeType === NodeType.Nested) { return "dictionary-key"; } if (typedNode.nodeType === NodeType.File) { return "file/path"; } if (typedNode.nodeType === NodeType.Markdown) { return getEmptyNode(typedNode); } return content; } if (!section || typeof section !== "object") { return section; } if (Array.isArray(section)) { return section.map( getEmptyNode ); } const mappedSectionObject = Object.entries(section).map(([key, value]) => [ key, getEmptyNode(value) ]); const mappedSectionArray = Object.fromEntries(mappedSectionObject); return mappedSectionArray; }; export { getEmptyNode }; //# sourceMappingURL=getEmptyNode.mjs.map