@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
1 lines • 3.28 kB
Source Map (JSON)
{"version":3,"file":"getDefaultNode.mjs","names":[],"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import {\n type ContentNode,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n): ContentNode => {\n const clonedContent = structuredClone(content);\n switch (nodeType) {\n case NodeType.Translation:\n return {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: Object.assign(\n {},\n ...locales.map((locale) => ({\n [locale]: structuredClone(clonedContent) ?? '',\n }))\n ),\n } as ContentNode;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: clonedContent ?? '',\n false: clonedContent ?? '',\n },\n } as ContentNode;\n\n case NodeType.Insertion:\n return {\n nodeType: NodeType.Insertion,\n [NodeType.Insertion]: {\n insertion: clonedContent ?? '',\n },\n } as unknown as ContentNode;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as ContentNode;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.File:\n return {\n nodeType: NodeType.File,\n [NodeType.File]: clonedContent ?? '',\n } as ContentNode;\n\n case NodeType.Object:\n return {\n newKey: clonedContent ?? '',\n } as unknown as ContentNode;\n\n case NodeType.Array:\n return [clonedContent ?? ''] as unknown as ContentNode;\n\n case NodeType.Text:\n return clonedContent ?? '';\n\n case NodeType.Number:\n return clonedContent ?? 0;\n\n case NodeType.Boolean:\n return clonedContent ?? true;\n\n default:\n return clonedContent ?? '';\n }\n};\n"],"mappings":";;;AAMA,MAAa,kBACX,UACA,SACA,YACgB;CAChB,MAAM,gBAAgB,gBAAgB,QAAQ;AAC9C,SAAQ,UAAR;EACE,KAAK,SAAS,YACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,cAAc,OAAO,OAC7B,EAAE,EACF,GAAG,QAAQ,KAAK,YAAY,GACzB,SAAS,gBAAgB,cAAc,IAAI,IAC7C,EAAE,CACJ;GACF;EAEH,KAAK,SAAS,YACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,cAAc,EACtB,KAAK,iBAAiB,IACvB;GACF;EAEH,KAAK,SAAS,UACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,YAAY;IACpB,MAAM,iBAAiB;IACvB,OAAO,iBAAiB;IACzB;GACF;EAEH,KAAK,SAAS,UACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,YAAY,EACpB,WAAW,iBAAiB,IAC7B;GACF;EAEH,KAAK,SAAS,OACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,SAAS,EACjB,eAAe,IAChB;GACF;EAEH,KAAK,SAAS,SACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,WAAW,iBAAiB;GACvC;EAEH,KAAK,SAAS,KACZ,QAAO;GACL,UAAU,SAAS;IAClB,SAAS,OAAO,iBAAiB;GACnC;EAEH,KAAK,SAAS,OACZ,QAAO,EACL,QAAQ,iBAAiB,IAC1B;EAEH,KAAK,SAAS,MACZ,QAAO,CAAC,iBAAiB,GAAG;EAE9B,KAAK,SAAS,KACZ,QAAO,iBAAiB;EAE1B,KAAK,SAAS,OACZ,QAAO,iBAAiB;EAE1B,KAAK,SAAS,QACZ,QAAO,iBAAiB;EAE1B,QACE,QAAO,iBAAiB"}