UNPKG

@intlayer/core

Version:

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

25 lines (23 loc) 1.21 kB
import { NodeType } from "@intlayer/types"; //#region src/dictionaryManipulator/getEmptyNode.ts 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)]); return Object.fromEntries(mappedSectionObject); }; //#endregion export { getEmptyNode }; //# sourceMappingURL=getEmptyNode.mjs.map