@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
1 lines • 1.57 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/dictionaryManipulator/getContentNodeByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\nexport const getContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = structuredClone(dictionaryContent);\n\n for (const keyObj of keyPath) {\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n currentValue = currentValue?.[keyObj.key];\n } else if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Condition ||\n keyObj.type === NodeType.Enumeration\n ) {\n currentValue = currentValue?.[keyObj.type][keyObj.key];\n } else if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n currentValue = currentValue?.[keyObj.type];\n }\n }\n\n return currentValue as ContentNode;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuC;AAGhC,MAAM,0BAA0B,CACrC,mBACA,YACgB;AAChB,MAAI,eAAoB,gBAAgB,iBAAiB;AAEzD,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,sBAAS,UAAU,OAAO,SAAS,sBAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WACE,OAAO,SAAS,sBAAS,eACzB,OAAO,SAAS,sBAAS,aACzB,OAAO,SAAS,sBAAS,aACzB;AACA,qBAAe,eAAe,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACvD,WACE,OAAO,SAAS,sBAAS,YACzB,OAAO,SAAS,sBAAS,aACzB,OAAO,SAAS,sBAAS,MACzB;AACA,qBAAe,eAAe,OAAO,IAAI;AAAA,IAC3C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}