@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
49 lines (47 loc) • 1.6 kB
JavaScript
import { NodeType } from "@intlayer/types";
//#region src/dictionaryManipulator/getDefaultNode.ts
const getDefaultNode = (nodeType, locales, content) => {
const clonedContent = structuredClone(content);
switch (nodeType) {
case NodeType.Translation: return {
nodeType: NodeType.Translation,
[NodeType.Translation]: Object.assign({}, ...locales.map((locale) => ({ [locale]: structuredClone(clonedContent) ?? "" })))
};
case NodeType.Enumeration: return {
nodeType: NodeType.Enumeration,
[NodeType.Enumeration]: { "1": clonedContent ?? "" }
};
case NodeType.Condition: return {
nodeType: NodeType.Condition,
[NodeType.Condition]: {
true: clonedContent ?? "",
false: clonedContent ?? ""
}
};
case NodeType.Insertion: return {
nodeType: NodeType.Insertion,
[NodeType.Insertion]: { insertion: clonedContent ?? "" }
};
case NodeType.Nested: return {
nodeType: NodeType.Nested,
[NodeType.Nested]: { dictionaryKey: "" }
};
case NodeType.Markdown: return {
nodeType: NodeType.Markdown,
[NodeType.Markdown]: clonedContent ?? ""
};
case NodeType.File: return {
nodeType: NodeType.File,
[NodeType.File]: clonedContent ?? ""
};
case NodeType.Object: return { newKey: clonedContent ?? "" };
case NodeType.Array: return [clonedContent ?? ""];
case NodeType.Text: return clonedContent ?? "";
case NodeType.Number: return clonedContent ?? 0;
case NodeType.Boolean: return clonedContent ?? true;
default: return clonedContent ?? "";
}
};
//#endregion
export { getDefaultNode };
//# sourceMappingURL=getDefaultNode.mjs.map