@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
25 lines (23 loc) • 1.31 kB
JavaScript
import * as NodeTypes from "@intlayer/types/nodeType";
//#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 === NodeTypes.TRANSLATION || typedNode.nodeType === NodeTypes.ENUMERATION || typedNode.nodeType === NodeTypes.PLURAL || typedNode.nodeType === NodeTypes.CONDITION || typedNode.nodeType === NodeTypes.INSERTION || typedNode.nodeType === NodeTypes.HTML) return getEmptyNode(content);
if (typedNode.nodeType === NodeTypes.NESTED) return "dictionary-key";
if (typedNode.nodeType === NodeTypes.FILE) return "file/path";
if (typedNode.nodeType === NodeTypes.MARKDOWN) return getEmptyNode(content);
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