@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
1 lines • 2.16 kB
Source Map (JSON)
{"version":3,"file":"removeContentNodeByKeyPath.mjs","names":["currentValue: any","parentValue: any","lastKey: string | number | null"],"sources":["../../../src/dictionaryManipulator/removeContentNodeByKeyPath.ts"],"sourcesContent":["import { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\n\nexport const removeContentNodeByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[]\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKey: string | number | null = null;\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object || keyObj.type === NodeType.Array) {\n lastKey = keyObj.key;\n currentValue = currentValue[keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.ReactNode ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKey = keyObj.type;\n currentValue = currentValue[keyObj.type];\n }\n }\n\n if (parentValue && lastKey !== null) {\n if (Array.isArray(parentValue)) {\n parentValue.splice(lastKey as unknown as number, 1);\n } else {\n delete parentValue[lastKey];\n }\n }\n\n return dictionaryContent;\n};\n"],"mappings":";;;AAEA,MAAa,8BACX,mBACA,YACgB;CAChB,IAAIA,eAAoB;CACxB,IAAIC,cAAmB;CACvB,IAAIC,UAAkC;AAEtC,MAAK,MAAM,UAAU,SAAS;AAC5B,gBAAc;AAEd,MAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;AAGrC,MACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,WACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO,MAAM,OAAO;;AAGlD,MACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,aAAU,OAAO;AACjB,kBAAe,aAAa,OAAO;;;AAIvC,KAAI,eAAe,YAAY,KAC7B,KAAI,MAAM,QAAQ,YAAY,CAC5B,aAAY,OAAO,SAA8B,EAAE;KAEnD,QAAO,YAAY;AAIvB,QAAO"}