@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
71 lines • 2.48 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var getEmptyNode_exports = {};
__export(getEmptyNode_exports, {
getEmptyNode: () => getEmptyNode
});
module.exports = __toCommonJS(getEmptyNode_exports);
var import_types = require('../types/index.cjs');
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 === import_types.NodeType.Translation || typedNode.nodeType === import_types.NodeType.Enumeration || typedNode.nodeType === import_types.NodeType.Condition || typedNode.nodeType === import_types.NodeType.Insertion) {
return getEmptyNode(content);
}
if (typedNode.nodeType === import_types.NodeType.Nested) {
return "dictionary-key";
}
if (typedNode.nodeType === import_types.NodeType.File) {
return "file/path";
}
if (typedNode.nodeType === import_types.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;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getEmptyNode
});
//# sourceMappingURL=getEmptyNode.cjs.map