@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
1 lines • 2.56 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/dictionaryManipulator/getEmptyNode.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getEmptyNode = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return '';\n }\n if (typeof section === 'number') {\n return 0;\n }\n if (typeof section === 'boolean') {\n return true;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion\n ) {\n return getEmptyNode(content as ContentNode);\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return 'dictionary-key';\n }\n\n if (typedNode.nodeType === NodeType.File) {\n return 'file/path';\n }\n\n if (typedNode.nodeType === NodeType.Markdown) {\n return getEmptyNode(typedNode);\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[]).map(\n getEmptyNode\n ) as unknown as ContentNode;\n }\n\n const mappedSectionObject = Object.entries(section).map(([key, value]) => [\n key,\n getEmptyNode(value as ContentNode),\n ]);\n\n const mappedSectionArray = Object.fromEntries(mappedSectionObject);\n\n return mappedSectionArray;\n};\n"],"mappings":"AAAA,SAA2C,gBAAgB;AAEpD,MAAM,eAAe,CAAC,YAAsC;AACjE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,WAChC;AACA,aAAO,aAAa,OAAsB;AAAA,IAC5C;AAEA,QAAI,UAAU,aAAa,SAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,aAAa,SAAS,MAAM;AACxC,aAAO;AAAA,IACT;AAEA,QAAI,UAAU,aAAa,SAAS,UAAU;AAC5C,aAAO,aAAa,SAAS;AAAA,IAC/B;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B;AAAA,MAChC;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,OAAO,QAAQ,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,IACxE;AAAA,IACA,aAAa,KAAoB;AAAA,EACnC,CAAC;AAED,QAAM,qBAAqB,OAAO,YAAY,mBAAmB;AAEjE,SAAO;AACT;","names":[]}