@intlayer/core 5.0.6 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +34 -29
  2. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
  3. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -1
  4. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
  5. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +84 -0
  6. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -0
  7. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +59 -0
  8. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -0
  9. package/dist/cjs/dictionaryManipulator/{getSectionType.cjs → getNodeType.cjs} +25 -16
  10. package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -0
  11. package/dist/cjs/dictionaryManipulator/index.cjs +9 -3
  12. package/dist/cjs/dictionaryManipulator/index.cjs.map +1 -1
  13. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +79 -0
  14. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -0
  15. package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
  16. package/dist/cjs/interpreter/getContent/index.cjs +0 -2
  17. package/dist/cjs/interpreter/getContent/index.cjs.map +1 -1
  18. package/dist/cjs/interpreter/getContent/plugins.cjs +3 -6
  19. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  20. package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
  21. package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
  22. package/dist/cjs/interpreter/getIntlayerAsync.cjs.map +1 -1
  23. package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
  24. package/dist/cjs/interpreter/index.cjs +0 -2
  25. package/dist/cjs/interpreter/index.cjs.map +1 -1
  26. package/dist/cjs/localization/getMultilingualUrls.cjs +1 -1
  27. package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
  28. package/dist/cjs/localization/getPathWithoutLocale.cjs +5 -1
  29. package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
  30. package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
  31. package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
  32. package/dist/cjs/transpiler/translation/types.cjs.map +1 -1
  33. package/dist/cjs/types/dictionary.cjs.map +1 -1
  34. package/dist/cjs/types/nodeType.cjs +4 -1
  35. package/dist/cjs/types/nodeType.cjs.map +1 -1
  36. package/dist/cjs/utils/isValidReactElement.cjs.map +1 -1
  37. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +34 -29
  38. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
  39. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -1
  40. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
  41. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +60 -0
  42. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -0
  43. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +35 -0
  44. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -0
  45. package/dist/esm/dictionaryManipulator/getNodeType.mjs +42 -0
  46. package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -0
  47. package/dist/esm/dictionaryManipulator/index.mjs +4 -1
  48. package/dist/esm/dictionaryManipulator/index.mjs.map +1 -1
  49. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +55 -0
  50. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -0
  51. package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
  52. package/dist/esm/interpreter/getContent/index.mjs +0 -1
  53. package/dist/esm/interpreter/getContent/index.mjs.map +1 -1
  54. package/dist/esm/interpreter/getContent/plugins.mjs +3 -6
  55. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  56. package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
  57. package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
  58. package/dist/esm/interpreter/getIntlayerAsync.mjs.map +1 -1
  59. package/dist/esm/interpreter/getNesting.mjs.map +1 -1
  60. package/dist/esm/interpreter/index.mjs +0 -1
  61. package/dist/esm/interpreter/index.mjs.map +1 -1
  62. package/dist/esm/localization/getMultilingualUrls.mjs +1 -1
  63. package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
  64. package/dist/esm/localization/getPathWithoutLocale.mjs +5 -1
  65. package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
  66. package/dist/esm/transpiler/enumeration/enumeration.mjs +4 -1
  67. package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
  68. package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
  69. package/dist/esm/types/nodeType.mjs +4 -1
  70. package/dist/esm/types/nodeType.mjs.map +1 -1
  71. package/dist/esm/utils/isValidReactElement.mjs.map +1 -1
  72. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
  73. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +5 -0
  74. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -0
  75. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts +3 -0
  76. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -0
  77. package/dist/types/dictionaryManipulator/getNodeType.d.ts +4 -0
  78. package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -0
  79. package/dist/types/dictionaryManipulator/index.d.ts +4 -1
  80. package/dist/types/dictionaryManipulator/index.d.ts.map +1 -1
  81. package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts +3 -0
  82. package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -0
  83. package/dist/types/interpreter/getContent/deepTransform.d.ts +1 -1
  84. package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
  85. package/dist/types/interpreter/getContent/index.d.ts +0 -1
  86. package/dist/types/interpreter/getContent/index.d.ts.map +1 -1
  87. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  88. package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
  89. package/dist/types/interpreter/getIntlayer.d.ts +1 -1
  90. package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
  91. package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -1
  92. package/dist/types/interpreter/getNesting.d.ts +1 -1
  93. package/dist/types/interpreter/getNesting.d.ts.map +1 -1
  94. package/dist/types/interpreter/index.d.ts +0 -1
  95. package/dist/types/interpreter/index.d.ts.map +1 -1
  96. package/dist/types/localization/getPathWithoutLocale.d.ts.map +1 -1
  97. package/dist/types/transpiler/enumeration/enumeration.d.ts +1 -1
  98. package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
  99. package/dist/types/transpiler/nesting/nesting.d.ts +1 -1
  100. package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
  101. package/dist/types/transpiler/translation/translation.d.ts +1 -1
  102. package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
  103. package/dist/types/transpiler/translation/types.d.ts +1 -1
  104. package/dist/types/transpiler/translation/types.d.ts.map +1 -1
  105. package/dist/types/types/dictionary.d.ts +3 -2
  106. package/dist/types/types/dictionary.d.ts.map +1 -1
  107. package/dist/types/types/nodeType.d.ts +5 -2
  108. package/dist/types/types/nodeType.d.ts.map +1 -1
  109. package/dist/types/utils/isValidReactElement.d.ts.map +1 -1
  110. package/package.json +14 -14
  111. package/dist/cjs/dictionaryManipulator/getSectionType.cjs.map +0 -1
  112. package/dist/esm/dictionaryManipulator/getSectionType.mjs +0 -33
  113. package/dist/esm/dictionaryManipulator/getSectionType.mjs.map +0 -1
  114. package/dist/types/dictionaryManipulator/getSectionType.d.ts +0 -4
  115. package/dist/types/dictionaryManipulator/getSectionType.d.ts.map +0 -1
@@ -26,65 +26,70 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
26
26
  let currentValue = dictionaryContent;
27
27
  let parentValue = null;
28
28
  let lastKeys = [];
29
- for (const keyObj of keyPath) {
29
+ for (let i = 0; i < keyPath.length; i++) {
30
+ const keyObj = keyPath[i];
30
31
  parentValue = currentValue;
31
32
  if (keyObj.type === import_types.NodeType.Object) {
32
33
  lastKeys = [keyObj.key];
33
- if (!currentValue[keyObj.key]) {
34
- currentValue = {
35
- ...currentValue,
36
- [keyObj.key]: {}
37
- };
34
+ if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") {
35
+ currentValue[keyObj.key] = {};
38
36
  }
39
37
  currentValue = currentValue[keyObj.key];
40
38
  } else if (keyObj.type === import_types.NodeType.Array) {
41
39
  lastKeys = [keyObj.key];
42
- if (!currentValue[keyObj.key]) {
40
+ if (!currentValue[keyObj.key] || typeof currentValue[keyObj.key] !== "object") {
43
41
  currentValue[keyObj.key] = {};
44
42
  }
45
43
  currentValue = currentValue[keyObj.key];
46
44
  } else if (keyObj.type === import_types.NodeType.Translation) {
47
45
  lastKeys = [import_types.NodeType.Translation, keyObj.key];
48
- if (!currentValue[import_types.NodeType.Translation]) {
49
- currentValue[import_types.NodeType.Translation] = {
50
- ...currentValue[import_types.NodeType.Translation],
51
- [keyObj.key]: newValue
52
- };
46
+ if (!currentValue[import_types.NodeType.Translation] || typeof currentValue[import_types.NodeType.Translation] !== "object") {
47
+ currentValue[import_types.NodeType.Translation] = {};
48
+ }
49
+ if (!currentValue[import_types.NodeType.Translation][keyObj.key] || typeof currentValue[import_types.NodeType.Translation][keyObj.key] !== "object") {
50
+ currentValue[import_types.NodeType.Translation][keyObj.key] = {};
53
51
  }
54
52
  currentValue = currentValue[import_types.NodeType.Translation][keyObj.key];
55
53
  } else if (keyObj.type === import_types.NodeType.Enumeration) {
56
54
  lastKeys = [import_types.NodeType.Enumeration, keyObj.key];
57
- if (!currentValue[import_types.NodeType.Enumeration]) {
58
- currentValue[import_types.NodeType.Enumeration] = {
59
- ...currentValue[import_types.NodeType.Enumeration],
60
- [keyObj.key]: newValue
61
- };
55
+ if (!currentValue[import_types.NodeType.Enumeration] || typeof currentValue[import_types.NodeType.Enumeration] !== "object") {
56
+ currentValue[import_types.NodeType.Enumeration] = {};
57
+ }
58
+ if (!currentValue[import_types.NodeType.Enumeration][keyObj.key] || typeof currentValue[import_types.NodeType.Enumeration][keyObj.key] !== "object") {
59
+ currentValue[import_types.NodeType.Enumeration][keyObj.key] = {};
62
60
  }
63
61
  currentValue = currentValue[import_types.NodeType.Enumeration][keyObj.key];
62
+ } else if (keyObj.type === import_types.NodeType.Condition) {
63
+ lastKeys = [import_types.NodeType.Condition, keyObj.key];
64
+ if (!currentValue[import_types.NodeType.Condition] || typeof currentValue[import_types.NodeType.Condition] !== "object") {
65
+ currentValue[import_types.NodeType.Condition] = {};
66
+ }
67
+ if (!currentValue[import_types.NodeType.Condition][keyObj.key] || typeof currentValue[import_types.NodeType.Condition][keyObj.key] !== "object") {
68
+ currentValue[import_types.NodeType.Condition][keyObj.key] = {};
69
+ }
70
+ currentValue = currentValue[import_types.NodeType.Condition][keyObj.key];
64
71
  } else if (keyObj.type === import_types.NodeType.Markdown) {
65
72
  lastKeys = [import_types.NodeType.Markdown];
66
- if (!currentValue[import_types.NodeType.Markdown]) {
67
- currentValue[import_types.NodeType.Markdown] = newValue;
73
+ if (!currentValue[import_types.NodeType.Markdown] || typeof currentValue[import_types.NodeType.Markdown] !== "object") {
74
+ currentValue[import_types.NodeType.Markdown] = "";
68
75
  }
69
76
  currentValue = currentValue[import_types.NodeType.Markdown];
70
77
  } else if (keyObj.type === import_types.NodeType.Nested) {
71
78
  lastKeys = [import_types.NodeType.Nested];
72
- if (!currentValue[import_types.NodeType.Nested]) {
73
- currentValue[import_types.NodeType.Nested] = newValue;
79
+ if (!currentValue[import_types.NodeType.Nested] || typeof currentValue[import_types.NodeType.Nested] !== "object") {
80
+ currentValue[import_types.NodeType.Nested] = {};
74
81
  }
75
82
  currentValue = currentValue[import_types.NodeType.Nested];
76
83
  }
77
- if (parentValue && lastKeys.length > 0) {
84
+ if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {
85
+ let target = parentValue;
78
86
  for (const key of lastKeys.slice(0, -1)) {
79
- parentValue = parentValue[key];
87
+ target = target[key];
80
88
  }
81
- if (
82
- // Remove the field if the new value is undefined
83
- typeof newValue === "undefined"
84
- ) {
85
- delete parentValue[lastKeys[lastKeys.length - 1]];
89
+ if (typeof newValue === "undefined") {
90
+ delete target[lastKeys[lastKeys.length - 1]];
86
91
  } else {
87
- parentValue[lastKeys[lastKeys.length - 1]] = newValue;
92
+ target[lastKeys[lastKeys.length - 1]] = newValue;
88
93
  }
89
94
  }
90
95
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (const keyObj of keyPath) {\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue = {\n ...currentValue,\n [keyObj.key]: {},\n };\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n\n if (!currentValue[keyObj.key]) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n\n if (!currentValue[NodeType.Translation]) {\n currentValue[NodeType.Translation] = {\n ...currentValue[NodeType.Translation],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n\n if (!currentValue[NodeType.Enumeration]) {\n currentValue[NodeType.Enumeration] = {\n ...currentValue[NodeType.Enumeration],\n [keyObj.key]: newValue,\n };\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Markdown) {\n lastKeys = [NodeType.Markdown];\n if (!currentValue[NodeType.Markdown]) {\n currentValue[NodeType.Markdown] = newValue;\n }\n currentValue = currentValue[NodeType.Markdown];\n } else if (keyObj.type === NodeType.Nested) {\n lastKeys = [NodeType.Nested];\n if (!currentValue[NodeType.Nested]) {\n currentValue[NodeType.Nested] = newValue;\n }\n currentValue = currentValue[NodeType.Nested];\n }\n\n // Assign the new value to the last key of the parent\n if (parentValue && lastKeys.length > 0) {\n for (const key of lastKeys.slice(0, -1)) {\n parentValue = parentValue[key];\n }\n if (\n // Remove the field if the new value is undefined\n typeof newValue === 'undefined'\n ) {\n delete parentValue[lastKeys[lastKeys.length - 1]];\n } else {\n parentValue[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuC;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,aAAW,UAAU,SAAS;AAC5B,kBAAc;AAEd,QAAI,OAAO,SAAS,sBAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,uBAAe;AAAA,UACb,GAAG;AAAA,UACH,CAAC,OAAO,GAAG,GAAG,CAAC;AAAA,QACjB;AAAA,MACF;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,sBAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AAEtB,UAAI,CAAC,aAAa,OAAO,GAAG,GAAG;AAC7B,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,iBAAW,CAAC,sBAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,sBAAS,WAAW,GAAG;AACvC,qBAAa,sBAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,sBAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,iBAAW,CAAC,sBAAS,aAAa,OAAO,GAAG;AAE5C,UAAI,CAAC,aAAa,sBAAS,WAAW,GAAG;AACvC,qBAAa,sBAAS,WAAW,IAAI;AAAA,UACnC,GAAG,aAAa,sBAAS,WAAW;AAAA,UACpC,CAAC,OAAO,GAAG,GAAG;AAAA,QAChB;AAAA,MACF;AACA,qBAAe,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,sBAAS,UAAU;AAC5C,iBAAW,CAAC,sBAAS,QAAQ;AAC7B,UAAI,CAAC,aAAa,sBAAS,QAAQ,GAAG;AACpC,qBAAa,sBAAS,QAAQ,IAAI;AAAA,MACpC;AACA,qBAAe,aAAa,sBAAS,QAAQ;AAAA,IAC/C,WAAW,OAAO,SAAS,sBAAS,QAAQ;AAC1C,iBAAW,CAAC,sBAAS,MAAM;AAC3B,UAAI,CAAC,aAAa,sBAAS,MAAM,GAAG;AAClC,qBAAa,sBAAS,MAAM,IAAI;AAAA,MAClC;AACA,qBAAe,aAAa,sBAAS,MAAM;AAAA,IAC7C;AAGA,QAAI,eAAe,SAAS,SAAS,GAAG;AACtC,iBAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,sBAAc,YAAY,GAAG;AAAA,MAC/B;AACA;AAAA;AAAA,QAEE,OAAO,aAAa;AAAA,QACpB;AACA,eAAO,YAAY,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,MAClD,OAAO;AACL,oBAAY,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../types';\nimport type { ContentNode } from '../types/dictionary';\n\ntype LastKeyType = string | number;\n\nexport const editDictionaryByKeyPath = (\n dictionaryContent: ContentNode,\n keyPath: KeyPath[],\n newValue: ContentNode\n): ContentNode => {\n let currentValue: any = dictionaryContent;\n let parentValue: any = null;\n let lastKeys: LastKeyType[] = [];\n\n for (let i = 0; i < keyPath.length; i++) {\n const keyObj = keyPath[i];\n parentValue = currentValue;\n\n if (keyObj.type === NodeType.Object) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Array) {\n lastKeys = [keyObj.key];\n if (\n !currentValue[keyObj.key] ||\n typeof currentValue[keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.key];\n } else if (keyObj.type === NodeType.Translation) {\n lastKeys = [NodeType.Translation, keyObj.key];\n if (\n !currentValue[NodeType.Translation] ||\n typeof currentValue[NodeType.Translation] !== 'object'\n ) {\n currentValue[NodeType.Translation] = {};\n }\n if (\n !currentValue[NodeType.Translation][keyObj.key] ||\n typeof currentValue[NodeType.Translation][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Translation][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n lastKeys = [NodeType.Enumeration, keyObj.key];\n if (\n !currentValue[NodeType.Enumeration] ||\n typeof currentValue[NodeType.Enumeration] !== 'object'\n ) {\n currentValue[NodeType.Enumeration] = {};\n }\n if (\n !currentValue[NodeType.Enumeration][keyObj.key] ||\n typeof currentValue[NodeType.Enumeration][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Enumeration][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n lastKeys = [NodeType.Condition, keyObj.key];\n if (\n !currentValue[NodeType.Condition] ||\n typeof currentValue[NodeType.Condition] !== 'object'\n ) {\n currentValue[NodeType.Condition] = {};\n }\n if (\n !currentValue[NodeType.Condition][keyObj.key] ||\n typeof currentValue[NodeType.Condition][keyObj.key] !== 'object'\n ) {\n currentValue[NodeType.Condition][keyObj.key] = {};\n }\n currentValue = currentValue[NodeType.Condition][keyObj.key];\n } else if (keyObj.type === NodeType.Markdown) {\n lastKeys = [NodeType.Markdown];\n if (\n !currentValue[NodeType.Markdown] ||\n typeof currentValue[NodeType.Markdown] !== 'object'\n ) {\n currentValue[NodeType.Markdown] = '';\n }\n currentValue = currentValue[NodeType.Markdown];\n } else if (keyObj.type === NodeType.Nested) {\n lastKeys = [NodeType.Nested];\n if (\n !currentValue[NodeType.Nested] ||\n typeof currentValue[NodeType.Nested] !== 'object'\n ) {\n currentValue[NodeType.Nested] = {};\n }\n currentValue = currentValue[NodeType.Nested];\n }\n\n // Only update the value when processing the last key in the keyPath.\n if (i === keyPath.length - 1 && parentValue && lastKeys.length > 0) {\n let target = parentValue;\n // Drill down if lastKeys contains more than one key.\n for (const key of lastKeys.slice(0, -1)) {\n target = target[key];\n }\n if (typeof newValue === 'undefined') {\n delete target[lastKeys[lastKeys.length - 1]];\n } else {\n target[lastKeys[lastKeys.length - 1]] = newValue;\n }\n }\n }\n return dictionaryContent;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuC;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,sBAAS,QAAQ;AACnC,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aAAa,OAAO,GAAG,KACxB,OAAO,aAAa,OAAO,GAAG,MAAM,UACpC;AACA,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,sBAAS,OAAO;AACzC,iBAAW,CAAC,OAAO,GAAG;AACtB,UACE,CAAC,aAAa,OAAO,GAAG,KACxB,OAAO,aAAa,OAAO,GAAG,MAAM,UACpC;AACA,qBAAa,OAAO,GAAG,IAAI,CAAC;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,GAAG;AAAA,IACxC,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,iBAAW,CAAC,sBAAS,aAAa,OAAO,GAAG;AAC5C,UACE,CAAC,aAAa,sBAAS,WAAW,KAClC,OAAO,aAAa,sBAAS,WAAW,MAAM,UAC9C;AACA,qBAAa,sBAAS,WAAW,IAAI,CAAC;AAAA,MACxC;AACA,UACE,CAAC,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG,KAC9C,OAAO,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG,MAAM,UAC1D;AACA,qBAAa,sBAAS,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MACpD;AACA,qBAAe,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,iBAAW,CAAC,sBAAS,aAAa,OAAO,GAAG;AAC5C,UACE,CAAC,aAAa,sBAAS,WAAW,KAClC,OAAO,aAAa,sBAAS,WAAW,MAAM,UAC9C;AACA,qBAAa,sBAAS,WAAW,IAAI,CAAC;AAAA,MACxC;AACA,UACE,CAAC,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG,KAC9C,OAAO,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG,MAAM,UAC1D;AACA,qBAAa,sBAAS,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MACpD;AACA,qBAAe,aAAa,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAC9D,WAAW,OAAO,SAAS,sBAAS,WAAW;AAC7C,iBAAW,CAAC,sBAAS,WAAW,OAAO,GAAG;AAC1C,UACE,CAAC,aAAa,sBAAS,SAAS,KAChC,OAAO,aAAa,sBAAS,SAAS,MAAM,UAC5C;AACA,qBAAa,sBAAS,SAAS,IAAI,CAAC;AAAA,MACtC;AACA,UACE,CAAC,aAAa,sBAAS,SAAS,EAAE,OAAO,GAAG,KAC5C,OAAO,aAAa,sBAAS,SAAS,EAAE,OAAO,GAAG,MAAM,UACxD;AACA,qBAAa,sBAAS,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAClD;AACA,qBAAe,aAAa,sBAAS,SAAS,EAAE,OAAO,GAAG;AAAA,IAC5D,WAAW,OAAO,SAAS,sBAAS,UAAU;AAC5C,iBAAW,CAAC,sBAAS,QAAQ;AAC7B,UACE,CAAC,aAAa,sBAAS,QAAQ,KAC/B,OAAO,aAAa,sBAAS,QAAQ,MAAM,UAC3C;AACA,qBAAa,sBAAS,QAAQ,IAAI;AAAA,MACpC;AACA,qBAAe,aAAa,sBAAS,QAAQ;AAAA,IAC/C,WAAW,OAAO,SAAS,sBAAS,QAAQ;AAC1C,iBAAW,CAAC,sBAAS,MAAM;AAC3B,UACE,CAAC,aAAa,sBAAS,MAAM,KAC7B,OAAO,aAAa,sBAAS,MAAM,MAAM,UACzC;AACA,qBAAa,sBAAS,MAAM,IAAI,CAAC;AAAA,MACnC;AACA,qBAAe,aAAa,sBAAS,MAAM;AAAA,IAC7C;AAGA,QAAI,MAAM,QAAQ,SAAS,KAAK,eAAe,SAAS,SAAS,GAAG;AAClE,UAAI,SAAS;AAEb,iBAAW,OAAO,SAAS,MAAM,GAAG,EAAE,GAAG;AACvC,iBAAS,OAAO,GAAG;AAAA,MACrB;AACA,UAAI,OAAO,aAAa,aAAa;AACnC,eAAO,OAAO,SAAS,SAAS,SAAS,CAAC,CAAC;AAAA,MAC7C,OAAO;AACL,eAAO,SAAS,SAAS,SAAS,CAAC,CAAC,IAAI;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
@@ -23,7 +23,7 @@ __export(getContentNodeByKeyPath_exports, {
23
23
  module.exports = __toCommonJS(getContentNodeByKeyPath_exports);
24
24
  var import_types = require('../types/index.cjs');
25
25
  const getContentNodeByKeyPath = (dictionaryContent, keyPath) => {
26
- let currentValue = JSON.parse(JSON.stringify(dictionaryContent ?? {}));
26
+ let currentValue = structuredClone(dictionaryContent ?? {});
27
27
  for (const keyObj of keyPath) {
28
28
  if (keyObj.type === import_types.NodeType.Object || keyObj.type === import_types.NodeType.Array) {
29
29
  currentValue = currentValue?.[keyObj.key];
@@ -1 +1 @@
1
- {"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 = JSON.parse(JSON.stringify(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 (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n currentValue = currentValue[NodeType.Condition];\n } else if (keyObj.type === NodeType.Markdown) {\n currentValue = currentValue[NodeType.Markdown];\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,KAAK,MAAM,KAAK,UAAU,qBAAqB,CAAC,CAAC,CAAC;AAE1E,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,sBAAS,UAAU,OAAO,SAAS,sBAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,qBAAe,eAAe,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,qBAAe,eAAe,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,sBAAS,WAAW;AAC7C,qBAAe,aAAa,sBAAS,SAAS;AAAA,IAChD,WAAW,OAAO,SAAS,sBAAS,UAAU;AAC5C,qBAAe,aAAa,sBAAS,QAAQ;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
1
+ {"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 (keyObj.type === NodeType.Translation) {\n currentValue = currentValue?.[NodeType.Translation][keyObj.key];\n } else if (keyObj.type === NodeType.Enumeration) {\n currentValue = currentValue?.[NodeType.Enumeration][keyObj.key];\n } else if (keyObj.type === NodeType.Condition) {\n currentValue = currentValue[NodeType.Condition];\n } else if (keyObj.type === NodeType.Markdown) {\n currentValue = currentValue[NodeType.Markdown];\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,qBAAqB,CAAC,CAAC;AAE/D,aAAW,UAAU,SAAS;AAC5B,QAAI,OAAO,SAAS,sBAAS,UAAU,OAAO,SAAS,sBAAS,OAAO;AACrE,qBAAe,eAAe,OAAO,GAAG;AAAA,IAC1C,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,qBAAe,eAAe,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,sBAAS,aAAa;AAC/C,qBAAe,eAAe,sBAAS,WAAW,EAAE,OAAO,GAAG;AAAA,IAChE,WAAW,OAAO,SAAS,sBAAS,WAAW;AAC7C,qBAAe,aAAa,sBAAS,SAAS;AAAA,IAChD,WAAW,OAAO,SAAS,sBAAS,UAAU;AAC5C,qBAAe,aAAa,sBAAS,QAAQ;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var getDefaultNode_exports = {};
20
+ __export(getDefaultNode_exports, {
21
+ getDefaultNode: () => getDefaultNode
22
+ });
23
+ module.exports = __toCommonJS(getDefaultNode_exports);
24
+ var import_types = require('../types/index.cjs');
25
+ const getDefaultNode = (nodeType, locales, content) => {
26
+ switch (nodeType) {
27
+ case import_types.NodeType.Translation:
28
+ return {
29
+ nodeType: import_types.NodeType.Translation,
30
+ [import_types.NodeType.Translation]: Object.assign(
31
+ {},
32
+ ...locales.map((locale) => ({
33
+ [locale]: content ?? ""
34
+ }))
35
+ )
36
+ };
37
+ case import_types.NodeType.Enumeration:
38
+ return {
39
+ nodeType: import_types.NodeType.Enumeration,
40
+ [import_types.NodeType.Enumeration]: {
41
+ "1": content ?? ""
42
+ }
43
+ };
44
+ case import_types.NodeType.Condition:
45
+ return {
46
+ nodeType: import_types.NodeType.Condition,
47
+ [import_types.NodeType.Condition]: {
48
+ true: content ?? "",
49
+ false: content ?? ""
50
+ }
51
+ };
52
+ case import_types.NodeType.Nested:
53
+ return {
54
+ nodeType: import_types.NodeType.Nested,
55
+ [import_types.NodeType.Nested]: {
56
+ dictionaryKey: ""
57
+ }
58
+ };
59
+ case import_types.NodeType.Markdown:
60
+ return {
61
+ nodeType: import_types.NodeType.Markdown,
62
+ [import_types.NodeType.Markdown]: content ?? ""
63
+ };
64
+ case import_types.NodeType.Object:
65
+ return {
66
+ newKey: content ?? ""
67
+ };
68
+ case import_types.NodeType.Array:
69
+ return [content ?? ""];
70
+ case import_types.NodeType.Text:
71
+ return content ?? "";
72
+ case import_types.NodeType.Number:
73
+ return content ?? 0;
74
+ case import_types.NodeType.Boolean:
75
+ return content ?? true;
76
+ default:
77
+ return content ?? "";
78
+ }
79
+ };
80
+ // Annotate the CommonJS export names for ESM import in node:
81
+ 0 && (module.exports = {
82
+ getDefaultNode
83
+ });
84
+ //# sourceMappingURL=getDefaultNode.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/getDefaultNode.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport type {\n TranslationContent,\n EnumerationContent,\n ConditionContent,\n NestedContent,\n MarkdownContent,\n} from '../transpiler';\nimport { type ContentNode, NodeType } from '../types';\n\nexport const getDefaultNode = (\n nodeType: NodeType,\n locales: LocalesValues[],\n content?: ContentNode\n) => {\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]: content ?? '',\n }))\n ),\n } as TranslationContent<ContentNode>;\n\n case NodeType.Enumeration:\n return {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: {\n '1': content ?? '',\n },\n } as EnumerationContent<ContentNode>;\n\n case NodeType.Condition:\n return {\n nodeType: NodeType.Condition,\n [NodeType.Condition]: {\n true: content ?? '',\n false: content ?? '',\n },\n } as ConditionContent<ContentNode>;\n\n case NodeType.Nested:\n return {\n nodeType: NodeType.Nested,\n [NodeType.Nested]: {\n dictionaryKey: '',\n },\n } as NestedContent;\n\n case NodeType.Markdown:\n return {\n nodeType: NodeType.Markdown,\n [NodeType.Markdown]: content ?? '',\n } as MarkdownContent;\n\n case NodeType.Object:\n return {\n newKey: content ?? '',\n } as Record<string, ContentNode>;\n\n case NodeType.Array:\n return [content ?? ''] as Record<number, ContentNode>;\n\n case NodeType.Text:\n return content ?? '';\n\n case NodeType.Number:\n return content ?? 0;\n\n case NodeType.Boolean:\n return content ?? true;\n\n default:\n return content ?? '';\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,mBAA2C;AAEpC,MAAM,iBAAiB,CAC5B,UACA,SACA,YACG;AACH,UAAQ,UAAU;AAAA,IAChB,KAAK,sBAAS;AACZ,aAAO;AAAA,QACL,UAAU,sBAAS;AAAA,QACnB,CAAC,sBAAS,WAAW,GAAG,OAAO;AAAA,UAC7B,CAAC;AAAA,UACD,GAAG,QAAQ,IAAI,CAAC,YAAY;AAAA,YAC1B,CAAC,MAAM,GAAG,WAAW;AAAA,UACvB,EAAE;AAAA,QACJ;AAAA,MACF;AAAA,IAEF,KAAK,sBAAS;AACZ,aAAO;AAAA,QACL,UAAU,sBAAS;AAAA,QACnB,CAAC,sBAAS,WAAW,GAAG;AAAA,UACtB,KAAK,WAAW;AAAA,QAClB;AAAA,MACF;AAAA,IAEF,KAAK,sBAAS;AACZ,aAAO;AAAA,QACL,UAAU,sBAAS;AAAA,QACnB,CAAC,sBAAS,SAAS,GAAG;AAAA,UACpB,MAAM,WAAW;AAAA,UACjB,OAAO,WAAW;AAAA,QACpB;AAAA,MACF;AAAA,IAEF,KAAK,sBAAS;AACZ,aAAO;AAAA,QACL,UAAU,sBAAS;AAAA,QACnB,CAAC,sBAAS,MAAM,GAAG;AAAA,UACjB,eAAe;AAAA,QACjB;AAAA,MACF;AAAA,IAEF,KAAK,sBAAS;AACZ,aAAO;AAAA,QACL,UAAU,sBAAS;AAAA,QACnB,CAAC,sBAAS,QAAQ,GAAG,WAAW;AAAA,MAClC;AAAA,IAEF,KAAK,sBAAS;AACZ,aAAO;AAAA,QACL,QAAQ,WAAW;AAAA,MACrB;AAAA,IAEF,KAAK,sBAAS;AACZ,aAAO,CAAC,WAAW,EAAE;AAAA,IAEvB,KAAK,sBAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,sBAAS;AACZ,aAAO,WAAW;AAAA,IAEpB,KAAK,sBAAS;AACZ,aAAO,WAAW;AAAA,IAEpB;AACE,aAAO,WAAW;AAAA,EACtB;AACF;","names":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var getNodeChildren_exports = {};
20
+ __export(getNodeChildren_exports, {
21
+ getNodeChildren: () => getNodeChildren
22
+ });
23
+ module.exports = __toCommonJS(getNodeChildren_exports);
24
+ var import_types = require('../types/index.cjs');
25
+ const getNodeChildren = (section) => {
26
+ if (typeof section === "string") {
27
+ return section;
28
+ }
29
+ if (typeof section === "number") {
30
+ return section;
31
+ }
32
+ if (typeof section === "boolean") {
33
+ return section;
34
+ }
35
+ if (typeof section?.nodeType === "string") {
36
+ const typedNode = section;
37
+ const content = typedNode[typedNode.nodeType];
38
+ if (typedNode.nodeType === import_types.NodeType.Translation || typedNode.nodeType === import_types.NodeType.Enumeration || typedNode.nodeType === import_types.NodeType.Condition) {
39
+ const firstKey = Object.keys(content)[0];
40
+ return content[firstKey];
41
+ }
42
+ if (typedNode.nodeType === import_types.NodeType.Nested) {
43
+ return void 0;
44
+ }
45
+ return content;
46
+ }
47
+ if (!section || typeof section !== "object") {
48
+ return section;
49
+ }
50
+ if (Array.isArray(section)) {
51
+ return section[0];
52
+ }
53
+ return section;
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ getNodeChildren
58
+ });
59
+ //# sourceMappingURL=getNodeChildren.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\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 ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\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[])[0];\n }\n\n return section;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2D;AAEpD,MAAM,kBAAkB,CAAC,YAAsC;AACpE,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,sBAAS,eAChC,UAAU,aAAa,sBAAS,eAChC,UAAU,aAAa,sBAAS,WAChC;AACA,YAAM,WAAW,OAAO,KAAK,OAAO,EAAE,CAAC;AACvC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,QAAI,UAAU,aAAa,sBAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B,CAAC;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
@@ -16,42 +16,51 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var getSectionType_exports = {};
20
- __export(getSectionType_exports, {
21
- getSectionType: () => getSectionType
19
+ var getNodeType_exports = {};
20
+ __export(getNodeType_exports, {
21
+ getNodeType: () => getNodeType
22
22
  });
23
- module.exports = __toCommonJS(getSectionType_exports);
23
+ module.exports = __toCommonJS(getNodeType_exports);
24
24
  var import_types = require('../types/index.cjs');
25
25
  var import_isValidReactElement = require('../utils/isValidReactElement.cjs');
26
- const getSectionType = (section) => {
27
- if (typeof section === "string") {
26
+ const getNodeType = (content) => {
27
+ if (typeof content === "string") {
28
28
  return import_types.NodeType.Text;
29
29
  }
30
- if (section?.nodeType === import_types.NodeType.Translation) {
30
+ if (content?.nodeType === import_types.NodeType.Translation) {
31
31
  return import_types.NodeType.Translation;
32
32
  }
33
- if (section?.nodeType === import_types.NodeType.Enumeration) {
33
+ if (content?.nodeType === import_types.NodeType.Enumeration) {
34
34
  return import_types.NodeType.Enumeration;
35
35
  }
36
- if (section?.nodeType === import_types.NodeType.Condition) {
36
+ if (content?.nodeType === import_types.NodeType.Condition) {
37
37
  return import_types.NodeType.Condition;
38
38
  }
39
- if (section?.nodeType === import_types.NodeType.Markdown) {
39
+ if (content?.nodeType === import_types.NodeType.Markdown) {
40
40
  return import_types.NodeType.Markdown;
41
41
  }
42
- if (section?.nodeType === import_types.NodeType.Nested) {
42
+ if (content?.nodeType === import_types.NodeType.Nested) {
43
43
  return import_types.NodeType.Nested;
44
44
  }
45
- if (Array.isArray(section)) {
45
+ if (Array.isArray(content)) {
46
46
  return import_types.NodeType.Array;
47
47
  }
48
- if ((0, import_isValidReactElement.isValidElement)(section)) {
48
+ if ((0, import_isValidReactElement.isValidElement)(content)) {
49
49
  return import_types.NodeType.ReactNode;
50
50
  }
51
- return import_types.NodeType.Object;
51
+ if (typeof content === "number") {
52
+ return import_types.NodeType.Number;
53
+ }
54
+ if (typeof content === "boolean") {
55
+ return import_types.NodeType.Boolean;
56
+ }
57
+ if (content && typeof content === "object") {
58
+ return import_types.NodeType.Object;
59
+ }
60
+ return import_types.NodeType.Unknown;
52
61
  };
53
62
  // Annotate the CommonJS export names for ESM import in node:
54
63
  0 && (module.exports = {
55
- getSectionType
64
+ getNodeType
56
65
  });
57
- //# sourceMappingURL=getSectionType.cjs.map
66
+ //# sourceMappingURL=getNodeType.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import type {\n TranslationContent,\n EnumerationContent,\n ConditionContent,\n MarkdownContent,\n NestedContent,\n} from '../transpiler';\nimport { NodeType, type DictionaryKeys } from '../types';\nimport type { ContentNode } from '../types/dictionary';\nimport { isValidElement } from '../utils/isValidReactElement';\n\nexport const getNodeType = (content: ContentNode): NodeType => {\n if (typeof content === 'string') {\n return NodeType.Text;\n }\n\n if ((content as TranslationContent)?.nodeType === NodeType.Translation) {\n return NodeType.Translation;\n }\n\n if ((content as EnumerationContent)?.nodeType === NodeType.Enumeration) {\n return NodeType.Enumeration;\n }\n\n if ((content as ConditionContent)?.nodeType === NodeType.Condition) {\n return NodeType.Condition;\n }\n\n if ((content as MarkdownContent)?.nodeType === NodeType.Markdown) {\n return NodeType.Markdown;\n }\n\n if (\n (content as NestedContent<DictionaryKeys>)?.nodeType === NodeType.Nested\n ) {\n return NodeType.Nested;\n }\n\n if (Array.isArray(content)) {\n return NodeType.Array;\n }\n\n if (isValidElement(content)) {\n return NodeType.ReactNode;\n }\n\n if (typeof content === 'number') {\n return NodeType.Number;\n }\n\n if (typeof content === 'boolean') {\n return NodeType.Boolean;\n }\n\n if (content && typeof content === 'object') {\n return NodeType.Object;\n }\n\n return NodeType.Unknown;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAA8C;AAE9C,iCAA+B;AAExB,MAAM,cAAc,CAAC,YAAmC;AAC7D,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAK,SAAgC,aAAa,sBAAS,aAAa;AACtE,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAK,SAAgC,aAAa,sBAAS,aAAa;AACtE,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAK,SAA8B,aAAa,sBAAS,WAAW;AAClE,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAK,SAA6B,aAAa,sBAAS,UAAU;AAChE,WAAO,sBAAS;AAAA,EAClB;AAEA,MACG,SAA2C,aAAa,sBAAS,QAClE;AACA,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,sBAAS;AAAA,EAClB;AAEA,UAAI,2CAAe,OAAO,GAAG;AAC3B,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO,sBAAS;AAAA,EAClB;AAEA,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,WAAO,sBAAS;AAAA,EAClB;AAEA,SAAO,sBAAS;AAClB;","names":[]}
@@ -17,15 +17,21 @@ var dictionaryManipulator_exports = {};
17
17
  module.exports = __toCommonJS(dictionaryManipulator_exports);
18
18
  __reExport(dictionaryManipulator_exports, require('./editDictionaryByKeyPath.cjs'), module.exports);
19
19
  __reExport(dictionaryManipulator_exports, require('./getContentNodeByKeyPath.cjs'), module.exports);
20
- __reExport(dictionaryManipulator_exports, require('./getSectionType.cjs'), module.exports);
20
+ __reExport(dictionaryManipulator_exports, require('./getNodeChildren.cjs'), module.exports);
21
21
  __reExport(dictionaryManipulator_exports, require('./removeContentNodeByKeyPath.cjs'), module.exports);
22
22
  __reExport(dictionaryManipulator_exports, require('./renameContentNodeByKeyPath.cjs'), module.exports);
23
+ __reExport(dictionaryManipulator_exports, require('./getNodeType.cjs'), module.exports);
24
+ __reExport(dictionaryManipulator_exports, require('./updateNodeChildren.cjs'), module.exports);
25
+ __reExport(dictionaryManipulator_exports, require('./getDefaultNode.cjs'), module.exports);
23
26
  // Annotate the CommonJS export names for ESM import in node:
24
27
  0 && (module.exports = {
25
28
  ...require('./editDictionaryByKeyPath.cjs'),
26
29
  ...require('./getContentNodeByKeyPath.cjs'),
27
- ...require('./getSectionType.cjs'),
30
+ ...require('./getNodeChildren.cjs'),
28
31
  ...require('./removeContentNodeByKeyPath.cjs'),
29
- ...require('./renameContentNodeByKeyPath.cjs')
32
+ ...require('./renameContentNodeByKeyPath.cjs'),
33
+ ...require('./getNodeType.cjs'),
34
+ ...require('./updateNodeChildren.cjs'),
35
+ ...require('./getDefaultNode.cjs')
30
36
  });
31
37
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getContentNodeByKeyPath';\nexport * from './getSectionType';\nexport * from './removeContentNodeByKeyPath';\nexport * from './renameContentNodeByKeyPath';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0CAAc,sCAAd;AACA,0CAAc,sCADd;AAEA,0CAAc,6BAFd;AAGA,0CAAc,yCAHd;AAIA,0CAAc,yCAJd;","names":[]}
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getContentNodeByKeyPath';\nexport * from './getNodeChildren';\nexport * from './removeContentNodeByKeyPath';\nexport * from './renameContentNodeByKeyPath';\nexport * from './getNodeType';\nexport * from './updateNodeChildren';\nexport * from './getDefaultNode';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0CAAc,sCAAd;AACA,0CAAc,sCADd;AAEA,0CAAc,8BAFd;AAGA,0CAAc,yCAHd;AAIA,0CAAc,yCAJd;AAKA,0CAAc,0BALd;AAMA,0CAAc,iCANd;AAOA,0CAAc,6BAPd;","names":[]}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var updateNodeChildren_exports = {};
20
+ __export(updateNodeChildren_exports, {
21
+ updateNodeChildren: () => updateNodeChildren
22
+ });
23
+ module.exports = __toCommonJS(updateNodeChildren_exports);
24
+ var import_types = require('../types/index.cjs');
25
+ const updateNodeChildren = (section, newChildren) => {
26
+ if (typeof section === "string") {
27
+ return newChildren;
28
+ }
29
+ if (typeof section === "number") {
30
+ return newChildren;
31
+ }
32
+ if (typeof section === "boolean") {
33
+ return newChildren;
34
+ }
35
+ if (typeof section?.nodeType === "string") {
36
+ const typedNode = section;
37
+ const content = typedNode[typedNode.nodeType];
38
+ if (typedNode.nodeType === import_types.NodeType.Translation || typedNode.nodeType === import_types.NodeType.Enumeration || typedNode.nodeType === import_types.NodeType.Condition) {
39
+ const newContent = Object.entries(content).reduce(
40
+ (acc, [key]) => ({
41
+ ...acc,
42
+ [key]: newChildren
43
+ }),
44
+ {}
45
+ );
46
+ return {
47
+ ...typedNode,
48
+ [typedNode.nodeType]: newContent
49
+ };
50
+ }
51
+ if (typedNode.nodeType === import_types.NodeType.Nested) {
52
+ return typedNode;
53
+ }
54
+ return {
55
+ ...typedNode,
56
+ [typedNode.nodeType]: newChildren
57
+ };
58
+ }
59
+ if (!section || typeof section !== "object") {
60
+ return newChildren;
61
+ }
62
+ if (Array.isArray(section)) {
63
+ return section.map(() => newChildren);
64
+ }
65
+ return Object.entries(
66
+ section
67
+ ).reduce(
68
+ (acc, [key]) => ({
69
+ ...acc,
70
+ [key]: newChildren
71
+ }),
72
+ {}
73
+ );
74
+ };
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ updateNodeChildren
78
+ });
79
+ //# sourceMappingURL=updateNodeChildren.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/dictionaryManipulator/updateNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const updateNodeChildren = <\n T extends ContentNode,\n U extends ContentNode,\n>(\n section: T,\n newChildren: U\n): ContentNode => {\n if (typeof section === 'string') {\n return newChildren;\n }\n if (typeof section === 'number') {\n return newChildren;\n }\n if (typeof section === 'boolean') {\n return newChildren;\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 ) {\n const newContent = Object.entries(content).reduce(\n (acc, [key]) => ({\n ...acc,\n [key]: newChildren,\n }),\n {} as Record<string, ContentNode>\n );\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newContent,\n };\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return typedNode;\n }\n\n return {\n ...typedNode,\n [typedNode.nodeType]: newChildren,\n };\n }\n\n if (!section || typeof section !== 'object') {\n return newChildren;\n }\n\n if (Array.isArray(section)) {\n return section.map(() => newChildren) as unknown as ContentNode;\n }\n\n return Object.entries(\n section as unknown as Record<string, ContentNode>\n ).reduce(\n (acc, [key]) => ({\n ...acc,\n [key]: newChildren,\n }),\n {} as Record<string, ContentNode>\n ) as ContentNode;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2D;AAEpD,MAAM,qBAAqB,CAIhC,SACA,gBACgB;AAChB,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,sBAAS,eAChC,UAAU,aAAa,sBAAS,eAChC,UAAU,aAAa,sBAAS,WAChC;AACA,YAAM,aAAa,OAAO,QAAQ,OAAO,EAAE;AAAA,QACzC,CAAC,KAAK,CAAC,GAAG,OAAO;AAAA,UACf,GAAG;AAAA,UACH,CAAC,GAAG,GAAG;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,UAAU,QAAQ,GAAG;AAAA,MACxB;AAAA,IACF;AAEA,QAAI,UAAU,aAAa,sBAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,UAAU,QAAQ,GAAG;AAAA,IACxB;AAAA,EACF;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,QAAQ,IAAI,MAAM,WAAW;AAAA,EACtC;AAEA,SAAO,OAAO;AAAA,IACZ;AAAA,EACF,EAAE;AAAA,IACA,CAAC,KAAK,CAAC,GAAG,OAAO;AAAA,MACf,GAAG;AAAA,MACH,CAAC,GAAG,GAAG;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/deepTransform.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type KeyPath, NodeType } from '../../types/index';\nimport { NodeProps } from './plugins';\n\n/**\n * Recursively traverses a node (object/array/primitive).\n * Applies the *first* plugin that can transform a node, then stops descending further.\n * If no plugin transforms it, it recurses into its children.\n */\nexport const deepTransformNode = (node: any, props: NodeProps): any => {\n // Otherwise, if it's an object, check if any plugin can handle it:\n for (const plugin of props.plugins ?? []) {\n if (plugin.canHandle(node)) {\n // Return the transformed node => do NOT recurse further\n return plugin.transform(node, props, (node: any, props: any) =>\n deepTransformNode(node, props)\n );\n }\n }\n\n // If it's null/undefined or not an object, just return it directly:\n if (node === null || typeof node !== 'object') {\n return node;\n }\n\n // If it's an array, transform each element:\n if (Array.isArray(node)) {\n return node.map((child, index) => {\n const childProps = {\n ...props,\n content: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n // If no plugin transforms it, we keep traversing its properties.\n const result: Record<string, any> = {};\n for (const key in node) {\n const childProps = {\n ...props,\n content: node[key],\n keyPath: [...props.keyPath, { type: NodeType.Object, key } as KeyPath],\n };\n result[key] = deepTransformNode(node[key], childProps);\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuC;AAQhC,MAAM,oBAAoB,CAAC,MAAW,UAA0B;AAErE,aAAW,UAAU,MAAM,WAAW,CAAC,GAAG;AACxC,QAAI,OAAO,UAAU,IAAI,GAAG;AAE1B,aAAO,OAAO;AAAA,QAAU;AAAA,QAAM;AAAA,QAAO,CAACA,OAAWC,WAC/C,kBAAkBD,OAAMC,MAAK;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAGA,MAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;AAC7C,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAO,KAAK,IAAI,CAAC,OAAO,UAAU;AAChC,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,OAAO,KAAK,MAAM;AAAA,QACrC;AAAA,MACF;AACA,aAAO,kBAAkB,OAAO,UAAU;AAAA,IAC5C,CAAC;AAAA,EACH;AAGA,QAAM,SAA8B,CAAC;AACrC,aAAW,OAAO,MAAM;AACtB,UAAM,aAAa;AAAA,MACjB,GAAG;AAAA,MACH,SAAS,KAAK,GAAG;AAAA,MACjB,SAAS,CAAC,GAAG,MAAM,SAAS,EAAE,MAAM,sBAAS,QAAQ,IAAI,CAAY;AAAA,IACvE;AACA,WAAO,GAAG,IAAI,kBAAkB,KAAK,GAAG,GAAG,UAAU;AAAA,EACvD;AAEA,SAAO;AACT;","names":["node","props"]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/deepTransform.ts"],"sourcesContent":["import { type KeyPath, NodeType } from '../../types/index';\nimport type { NodeProps } from './plugins';\n\n/**\n * Recursively traverses a node (object/array/primitive).\n * Applies the *first* plugin that can transform a node, then stops descending further.\n * If no plugin transforms it, it recurses into its children.\n */\nexport const deepTransformNode = (node: any, props: NodeProps): any => {\n // Otherwise, if it's an object, check if any plugin can handle it:\n for (const plugin of props.plugins ?? []) {\n if (plugin.canHandle(node)) {\n // Return the transformed node => do NOT recurse further\n return plugin.transform(node, props, (node: any, props: any) =>\n deepTransformNode(node, props)\n );\n }\n }\n\n // If it's null/undefined or not an object, just return it directly:\n if (node === null || typeof node !== 'object') {\n return node;\n }\n\n // If it's an array, transform each element:\n if (Array.isArray(node)) {\n return node.map((child, index) => {\n const childProps = {\n ...props,\n content: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n // If no plugin transforms it, we keep traversing its properties.\n const result: Record<string, any> = {};\n for (const key in node) {\n const childProps = {\n ...props,\n content: node[key],\n keyPath: [...props.keyPath, { type: NodeType.Object, key } as KeyPath],\n };\n result[key] = deepTransformNode(node[key], childProps);\n }\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAuC;AAQhC,MAAM,oBAAoB,CAAC,MAAW,UAA0B;AAErE,aAAW,UAAU,MAAM,WAAW,CAAC,GAAG;AACxC,QAAI,OAAO,UAAU,IAAI,GAAG;AAE1B,aAAO,OAAO;AAAA,QAAU;AAAA,QAAM;AAAA,QAAO,CAACA,OAAWC,WAC/C,kBAAkBD,OAAMC,MAAK;AAAA,MAC/B;AAAA,IACF;AAAA,EACF;AAGA,MAAI,SAAS,QAAQ,OAAO,SAAS,UAAU;AAC7C,WAAO;AAAA,EACT;AAGA,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,WAAO,KAAK,IAAI,CAAC,OAAO,UAAU;AAChC,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,OAAO,KAAK,MAAM;AAAA,QACrC;AAAA,MACF;AACA,aAAO,kBAAkB,OAAO,UAAU;AAAA,IAC5C,CAAC;AAAA,EACH;AAGA,QAAM,SAA8B,CAAC;AACrC,aAAW,OAAO,MAAM;AACtB,UAAM,aAAa;AAAA,MACjB,GAAG;AAAA,MACH,SAAS,KAAK,GAAG;AAAA,MACjB,SAAS,CAAC,GAAG,MAAM,SAAS,EAAE,MAAM,sBAAS,QAAQ,IAAI,CAAY;AAAA,IACvE;AACA,WAAO,GAAG,IAAI,kBAAkB,KAAK,GAAG,GAAG,UAAU;AAAA,EACvD;AAEA,SAAO;AACT;","names":["node","props"]}
@@ -15,12 +15,10 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var getContent_exports = {};
17
17
  module.exports = __toCommonJS(getContent_exports);
18
- __reExport(getContent_exports, require('../getDictionary.cjs'), module.exports);
19
18
  __reExport(getContent_exports, require('./deepTransform.cjs'), module.exports);
20
19
  __reExport(getContent_exports, require('./plugins.cjs'), module.exports);
21
20
  // Annotate the CommonJS export names for ESM import in node:
22
21
  0 && (module.exports = {
23
- ...require('../getDictionary.cjs'),
24
22
  ...require('./deepTransform.cjs'),
25
23
  ...require('./plugins.cjs')
26
24
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from '../getDictionary';\nexport * from './deepTransform';\nexport * from './plugins';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,6BAAd;AACA,+BAAc,4BADd;AAEA,+BAAc,sBAFd;","names":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './plugins';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,4BAAd;AACA,+BAAc,sBADd;","names":[]}
@@ -25,10 +25,10 @@ __export(plugins_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(plugins_exports);
27
27
  var import_types = require('../../types/index.cjs');
28
- var import_getTranslation = require('../getTranslation.cjs');
29
- var import_getEnumeration = require('../getEnumeration.cjs');
30
28
  var import_getCondition = require('../getCondition.cjs');
29
+ var import_getEnumeration = require('../getEnumeration.cjs');
31
30
  var import_getNesting = require('../getNesting.cjs');
31
+ var import_getTranslation = require('../getTranslation.cjs');
32
32
  const translationPlugin = (locale) => ({
33
33
  canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Translation,
34
34
  transform: (node, props, deepTransformNode) => {
@@ -96,10 +96,7 @@ const conditionPlugin = {
96
96
  };
97
97
  const nestedPlugin = {
98
98
  canHandle: (node) => typeof node === "object" && node?.nodeType === import_types.NodeType.Nested,
99
- transform: (node, props) => (
100
- // @ts-ignore
101
- (0, import_getNesting.getNesting)(node.nested.dictionaryKey, node.nested.path, props)
102
- )
99
+ transform: (node, props) => (0, import_getNesting.getNesting)(node.nested.dictionaryKey, node.nested.path, props)
103
100
  };
104
101
  // Annotate the CommonJS export names for ESM import in node:
105
102
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { Locales, LocalesValues } from '@intlayer/config/client';\n\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { getTranslation } from '../getTranslation';\nimport { getEnumeration } from '../getEnumeration';\nimport { getCondition } from '../getCondition';\nimport { type GetNestingResult, getNesting } from '../getNesting';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (locale: LocalesValues): Plugins => ({\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node.translation);\n\n for (const key in result) {\n const childProps = {\n ...props,\n content: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node.enumeration);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n content: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node.condition);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n content: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n // @ts-ignore\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n content?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n nested: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAA4D;AAO5D,4BAA+B;AAC/B,4BAA+B;AAC/B,0BAA6B;AAC7B,wBAAkD;AAqC3C,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS,OAAO,GAAqC;AAAA,QACrD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,eAAO,sCAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,iBAAqB,sCAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,SAAS;AAE7C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,cAAmB,kCAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB;AAAA;AAAA,QAE/B,8BAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AAAA;AACjE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\n\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (locale: LocalesValues): Plugins => ({\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node.translation);\n\n for (const key in result) {\n const childProps = {\n ...props,\n content: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node.enumeration);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n content: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node.condition);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n content: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n content?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n nested: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,mBAA4D;AAC5D,0BAA6B;AAC7B,4BAA+B;AAC/B,wBAAkD;AAClD,4BAA+B;AAqCxB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS,OAAO,GAAqC;AAAA,QACrD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,eAAO,sCAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,WAAW;AAE/C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,iBAAqB,sCAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,SAAS;AAE7C,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,sBAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,cAAmB,kCAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,sBAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,cAC/B,8BAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;","names":[]}