@intlayer/core 5.3.6 → 5.3.8

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.
@@ -59,13 +59,17 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
59
59
  }
60
60
  currentValue = currentValue[keyObj.type][keyObj.key];
61
61
  }
62
- if (keyObj.type === import_types.NodeType.Markdown || keyObj.type === import_types.NodeType.Insertion || keyObj.type === import_types.NodeType.File) {
62
+ if (keyObj.type === import_types.NodeType.Markdown || keyObj.type === import_types.NodeType.Insertion) {
63
63
  lastKeys = [keyObj.type];
64
64
  if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") {
65
65
  currentValue[keyObj.type] = "";
66
66
  }
67
67
  currentValue = currentValue[keyObj.type];
68
68
  }
69
+ if (keyObj.type === import_types.NodeType.File) {
70
+ lastKeys = ["content"];
71
+ currentValue = currentValue["content"];
72
+ }
69
73
  if (keyObj.type) {
70
74
  currentValue = currentValue;
71
75
  }
@@ -81,6 +85,11 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
81
85
  }
82
86
  }
83
87
  }
88
+ console.log({
89
+ dictionaryContent,
90
+ keyPath,
91
+ newValue
92
+ });
84
93
  return dictionaryContent;
85
94
  };
86
95
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
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 if (keyPath.length === 0) {\n return newValue;\n }\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 || 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 }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n\n currentValue = currentValue;\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\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,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,sBAAS,UAAU,OAAO,SAAS,sBAAS,OAAO;AACrE,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;AAEA,QACE,OAAO,SAAS,sBAAS,eACzB,OAAO,SAAS,sBAAS,aACzB;AACA,iBAAW,CAAC,OAAO,MAAM,OAAO,GAAG;AACnC,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI,CAAC;AAAA,MAC/B;AACA,UACE,CAAC,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,KACrC,OAAO,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,MAAM,UACjD;AACA,qBAAa,OAAO,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAC3C;AACA,qBAAe,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACrD;AAEA,QACE,OAAO,SAAS,sBAAS,eACzB,OAAO,SAAS,sBAAS,WACzB;AACA,iBAAW,CAAC,OAAO,MAAM,OAAO,GAAG;AACnC,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI,CAAC;AAAA,MAC/B;AACA,UACE,CAAC,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,KACrC,OAAO,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,MAAM,UACjD;AACA,qBAAa,OAAO,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAC3C;AACA,qBAAe,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACrD;AAEA,QACE,OAAO,SAAS,sBAAS,YACzB,OAAO,SAAS,sBAAS,aACzB,OAAO,SAAS,sBAAS,MACzB;AACA,iBAAW,CAAC,OAAO,IAAI;AACvB,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,IAAI;AAAA,IACzC;AAEA,QAAI,OAAO,MAAM;AAGf,qBAAe;AAAA,IACjB;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;AAEA,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 if (keyPath.length === 0) {\n return newValue;\n }\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 || 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 }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n\n currentValue = currentValue['content'];\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n\n currentValue = currentValue;\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\n console.log({\n dictionaryContent,\n keyPath,\n newValue,\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,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,sBAAS,UAAU,OAAO,SAAS,sBAAS,OAAO;AACrE,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;AAEA,QACE,OAAO,SAAS,sBAAS,eACzB,OAAO,SAAS,sBAAS,aACzB;AACA,iBAAW,CAAC,OAAO,MAAM,OAAO,GAAG;AACnC,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI,CAAC;AAAA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AAG,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;AAEA,UAAQ,IAAI;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO;AACT;","names":[]}
@@ -17,9 +17,11 @@ var getContent_exports = {};
17
17
  module.exports = __toCommonJS(getContent_exports);
18
18
  __reExport(getContent_exports, require('./deepTransform.cjs'), module.exports);
19
19
  __reExport(getContent_exports, require('./plugins.cjs'), module.exports);
20
+ __reExport(getContent_exports, require('./getContent.cjs'), module.exports);
20
21
  // Annotate the CommonJS export names for ESM import in node:
21
22
  0 && (module.exports = {
22
23
  ...require('./deepTransform.cjs'),
23
- ...require('./plugins.cjs')
24
+ ...require('./plugins.cjs'),
25
+ ...require('./getContent.cjs')
24
26
  });
25
27
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './plugins';\nexport * from './getContent';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,4BAAd;AACA,+BAAc,sBADd;AAEA,+BAAc,yBAFd;","names":[]}
@@ -23,6 +23,7 @@ __reExport(interpreter_exports, require('./getDictionary.cjs'), module.exports);
23
23
  __reExport(interpreter_exports, require('./getIntlayerAsync.cjs'), module.exports);
24
24
  __reExport(interpreter_exports, require('./getTranslation.cjs'), module.exports);
25
25
  __reExport(interpreter_exports, require('./getCondition.cjs'), module.exports);
26
+ __reExport(interpreter_exports, require('./getContent/index.cjs'), module.exports);
26
27
  // Annotate the CommonJS export names for ESM import in node:
27
28
  0 && (module.exports = {
28
29
  ...require('./getContent/index.cjs'),
@@ -32,6 +33,7 @@ __reExport(interpreter_exports, require('./getCondition.cjs'), module.exports);
32
33
  ...require('./getDictionary.cjs'),
33
34
  ...require('./getIntlayerAsync.cjs'),
34
35
  ...require('./getTranslation.cjs'),
35
- ...require('./getCondition.cjs')
36
+ ...require('./getCondition.cjs'),
37
+ ...require('./getContent/index.cjs')
36
38
  });
37
39
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/index.ts"],"sourcesContent":["export * from './getContent/index';\nexport * from './getNesting';\nexport * from './getEnumeration';\nexport * from './getIntlayer';\nexport * from './getDictionary';\nexport * from './getIntlayerAsync';\nexport * from './getTranslation';\nexport * from './getCondition';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,+BAAd;AACA,gCAAc,yBADd;AAEA,gCAAc,6BAFd;AAGA,gCAAc,0BAHd;AAIA,gCAAc,4BAJd;AAKA,gCAAc,+BALd;AAMA,gCAAc,6BANd;AAOA,gCAAc,2BAPd;","names":[]}
1
+ {"version":3,"sources":["../../../src/interpreter/index.ts"],"sourcesContent":["export * from './getContent/index';\nexport * from './getNesting';\nexport * from './getEnumeration';\nexport * from './getIntlayer';\nexport * from './getDictionary';\nexport * from './getIntlayerAsync';\nexport * from './getTranslation';\nexport * from './getCondition';\nexport * from './getContent/index';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,+BAAd;AACA,gCAAc,yBADd;AAEA,gCAAc,6BAFd;AAGA,gCAAc,0BAHd;AAIA,gCAAc,4BAJd;AAKA,gCAAc,+BALd;AAMA,gCAAc,6BANd;AAOA,gCAAc,2BAPd;AAQA,gCAAc,+BARd;","names":[]}
@@ -21,21 +21,33 @@ __export(markdown_exports, {
21
21
  md: () => markdown
22
22
  });
23
23
  module.exports = __toCommonJS(markdown_exports);
24
+ var import_getContent = require('../../interpreter/getContent/getContent.cjs');
24
25
  var import_types = require('../../types/index.cjs');
25
26
  var import_getMarkdownMetadata = require('./getMarkdownMetadata.cjs');
27
+ const awaitContent = async (content) => {
28
+ if (typeof content === "string" || typeof content === "object") {
29
+ return content;
30
+ }
31
+ if (typeof content === "function") {
32
+ return content();
33
+ }
34
+ if (typeof content.then === "function") {
35
+ return await content;
36
+ }
37
+ };
26
38
  const markdown = (content) => {
27
- const getMetadata = () => {
28
- if (typeof content === "string") {
29
- return (0, import_getMarkdownMetadata.getMarkdownMetadata)(content);
30
- }
31
- if (typeof content === "function") {
32
- return () => (0, import_getMarkdownMetadata.getMarkdownMetadata)(content());
33
- } else if (typeof content.then === "function") {
34
- return async () => (0, import_getMarkdownMetadata.getMarkdownMetadata)(await content);
39
+ const metadata = async () => {
40
+ const awaitedContent = await awaitContent(content);
41
+ const flatContent = (0, import_getContent.getContent)(awaitedContent, {
42
+ dictionaryKey: "",
43
+ keyPath: []
44
+ });
45
+ if (typeof flatContent === "string") {
46
+ return (0, import_getMarkdownMetadata.getMarkdownMetadata)(flatContent);
35
47
  }
36
48
  };
37
49
  return (0, import_types.formatNodeType)(import_types.NodeType.Markdown, content, {
38
- metadata: getMetadata()
50
+ metadata
39
51
  });
40
52
  };
41
53
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/markdown/markdown.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getMarkdownMetadata } from './getMarkdownMetadata';\n\nexport type MarkdownContentConstructor<\n T extends Record<string, any> = {},\n Content = unknown,\n> = TypedNodeModel<NodeType.Markdown, Content, T>;\n\nexport type MarkdownContent<Content = unknown> = MarkdownContentConstructor<{\n metadata?: Record<string, any>;\n}>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * markdown('## Hello world!');\n * ```\n *\n */\nconst markdown = <Content = unknown>(content: Content): MarkdownContent => {\n const getMetadata = () => {\n if (typeof content === 'string') {\n return getMarkdownMetadata(content);\n }\n if (typeof content === 'function') {\n return () => getMarkdownMetadata(content());\n } else if (typeof (content as Promise<string>).then === 'function') {\n return async () =>\n getMarkdownMetadata(await (content as Promise<string>));\n }\n };\n\n return formatNodeType(NodeType.Markdown, content as string, {\n metadata: getMetadata(),\n });\n};\n\nexport { markdown as md };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAIO;AACP,iCAAoC;AAuBpC,MAAM,WAAW,CAAoB,YAAsC;AACzE,QAAM,cAAc,MAAM;AACxB,QAAI,OAAO,YAAY,UAAU;AAC/B,iBAAO,gDAAoB,OAAO;AAAA,IACpC;AACA,QAAI,OAAO,YAAY,YAAY;AACjC,aAAO,UAAM,gDAAoB,QAAQ,CAAC;AAAA,IAC5C,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,aAAO,gBACL,gDAAoB,MAAO,OAA2B;AAAA,IAC1D;AAAA,EACF;AAEA,aAAO,6BAAe,sBAAS,UAAU,SAAmB;AAAA,IAC1D,UAAU,YAAY;AAAA,EACxB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/markdown/markdown.ts"],"sourcesContent":["import { getContent } from '../../interpreter/getContent/getContent';\nimport {\n ContentNode,\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getMarkdownMetadata } from './getMarkdownMetadata';\n\nexport type MarkdownContentConstructor<\n T extends Record<string, any> = {},\n Content = unknown,\n> = TypedNodeModel<NodeType.Markdown, Content, T>;\n\nexport type MarkdownContent<Content = unknown> = MarkdownContentConstructor<{\n metadata?: Record<string, any>;\n}>;\n\nconst awaitContent = async (content: any) => {\n if (typeof content === 'string' || typeof content === 'object') {\n return content as any;\n }\n\n if (typeof content === 'function') {\n return content();\n }\n if (typeof content.then === 'function') {\n return await content;\n }\n};\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * markdown('## Hello world!');\n * ```\n *\n */\nconst markdown = <Content = unknown>(content: Content): MarkdownContent => {\n const metadata = async () => {\n const awaitedContent = await awaitContent(content);\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite.\n const flatContent = getContent(awaitedContent, {\n dictionaryKey: '',\n keyPath: [],\n });\n\n if (typeof flatContent === 'string') {\n return getMarkdownMetadata(flatContent);\n }\n };\n\n return formatNodeType(NodeType.Markdown, content as string, {\n metadata,\n });\n};\n\nexport { markdown as md };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA2B;AAC3B,mBAKO;AACP,iCAAoC;AAWpC,MAAM,eAAe,OAAO,YAAiB;AAC3C,MAAI,OAAO,YAAY,YAAY,OAAO,YAAY,UAAU;AAC9D,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,YAAY;AACjC,WAAO,QAAQ;AAAA,EACjB;AACA,MAAI,OAAO,QAAQ,SAAS,YAAY;AACtC,WAAO,MAAM;AAAA,EACf;AACF;AAcA,MAAM,WAAW,CAAoB,YAAsC;AACzE,QAAM,WAAW,YAAY;AAC3B,UAAM,iBAAiB,MAAM,aAAa,OAAO;AAGjD,UAAM,kBAAc,8BAAW,gBAAgB;AAAA,MAC7C,eAAe;AAAA,MACf,SAAS,CAAC;AAAA,IACZ,CAAC;AAED,QAAI,OAAO,gBAAgB,UAAU;AACnC,iBAAO,gDAAoB,WAAW;AAAA,IACxC;AAAA,EACF;AAEA,aAAO,6BAAe,sBAAS,UAAU,SAAmB;AAAA,IAC1D;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -36,13 +36,17 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
36
36
  }
37
37
  currentValue = currentValue[keyObj.type][keyObj.key];
38
38
  }
39
- if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion || keyObj.type === NodeType.File) {
39
+ if (keyObj.type === NodeType.Markdown || keyObj.type === NodeType.Insertion) {
40
40
  lastKeys = [keyObj.type];
41
41
  if (!currentValue[keyObj.type] || typeof currentValue[keyObj.type] !== "object") {
42
42
  currentValue[keyObj.type] = "";
43
43
  }
44
44
  currentValue = currentValue[keyObj.type];
45
45
  }
46
+ if (keyObj.type === NodeType.File) {
47
+ lastKeys = ["content"];
48
+ currentValue = currentValue["content"];
49
+ }
46
50
  if (keyObj.type) {
47
51
  currentValue = currentValue;
48
52
  }
@@ -58,6 +62,11 @@ const editDictionaryByKeyPath = (dictionaryContent, keyPath, newValue) => {
58
62
  }
59
63
  }
60
64
  }
65
+ console.log({
66
+ dictionaryContent,
67
+ keyPath,
68
+ newValue
69
+ });
61
70
  return dictionaryContent;
62
71
  };
63
72
  export {
@@ -1 +1 @@
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 if (keyPath.length === 0) {\n return newValue;\n }\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 || 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 }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion ||\n keyObj.type === NodeType.File\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n\n currentValue = currentValue;\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\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,M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AO,GAAG,MAAM,UACjD;AACA,qBAAa,OAAO,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAC3C;AACA,qBAAe,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACrD;AAEA,QACE,OAAO,SAAS,SAAS,YACzB,OAAO,SAAS,SAAS,aACzB,OAAO,SAAS,SAAS,MACzB;AACA,iBAAW,CAAC,OAAO,IAAI;AACvB,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI;AAAA,MAC9B;AACA,qBAAe,aAAa,OAAO,IAAI;AAAA,IACzC;AAEA,QAAI,OAAO,MAAM;AAGf,qBAAe;AAAA,IACjB;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;AAEA,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 if (keyPath.length === 0) {\n return newValue;\n }\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 || 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 }\n\n if (\n keyObj.type === NodeType.Translation ||\n keyObj.type === NodeType.Enumeration\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Enumeration ||\n keyObj.type === NodeType.Condition\n ) {\n lastKeys = [keyObj.type, keyObj.key];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = {};\n }\n if (\n !currentValue[keyObj.type][keyObj.key] ||\n typeof currentValue[keyObj.type][keyObj.key] !== 'object'\n ) {\n currentValue[keyObj.type][keyObj.key] = {};\n }\n currentValue = currentValue[keyObj.type][keyObj.key];\n }\n\n if (\n keyObj.type === NodeType.Markdown ||\n keyObj.type === NodeType.Insertion\n ) {\n lastKeys = [keyObj.type];\n if (\n !currentValue[keyObj.type] ||\n typeof currentValue[keyObj.type] !== 'object'\n ) {\n currentValue[keyObj.type] = '';\n }\n currentValue = currentValue[keyObj.type];\n }\n\n if (keyObj.type === NodeType.File) {\n lastKeys = ['content'];\n\n currentValue = currentValue['content'];\n }\n\n if (keyObj.type) {\n // No treated TypedNode\n\n currentValue = currentValue;\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\n console.log({\n dictionaryContent,\n keyPath,\n newValue,\n });\n\n return dictionaryContent;\n};\n"],"mappings":"AAAA,SAAuB,gBAAgB;AAKhC,MAAM,0BAA0B,CACrC,mBACA,SACA,aACgB;AAChB,MAAI,eAAoB;AACxB,MAAI,cAAmB;AACvB,MAAI,WAA0B,CAAC;AAE/B,MAAI,QAAQ,WAAW,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,UAAM,SAAS,QAAQ,CAAC;AACxB,kBAAc;AAEd,QAAI,OAAO,SAAS,SAAS,UAAU,OAAO,SAAS,SAAS,OAAO;AACrE,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;AAEA,QACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,SAAS,aACzB;AACA,iBAAW,CAAC,OAAO,MAAM,OAAO,GAAG;AACnC,UACE,CAAC,aAAa,OAAO,IAAI,KACzB,OAAO,aAAa,OAAO,IAAI,MAAM,UACrC;AACA,qBAAa,OAAO,IAAI,IAAI,CAAC;AAAA,MAC/B;AACA,UACE,CAAC,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,KACrC,OAAO,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG,MAAM,UACjD;AACA,qBAAa,OAAO,IAAI,EAAE,OAAO,GAAG,IAAI,CAAC;AAAA,MAC3C;AACA,qBAAe,aAAa,OAAO,IAAI,EAAE,OAAO,GAAG;AAAA,IACrD;AAEA,QACE,OAAO,SAAS,SAAS,eACzB,OAAO,SAAS,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AAED,SAAO;AACT;","names":[]}
@@ -1,3 +1,4 @@
1
1
  export * from "./deepTransform.mjs";
2
2
  export * from "./plugins.mjs";
3
+ export * from "./getContent.mjs";
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './plugins';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './plugins';\nexport * from './getContent';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -6,4 +6,5 @@ export * from "./getDictionary.mjs";
6
6
  export * from "./getIntlayerAsync.mjs";
7
7
  export * from "./getTranslation.mjs";
8
8
  export * from "./getCondition.mjs";
9
+ export * from "./getContent/index.mjs";
9
10
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/interpreter/index.ts"],"sourcesContent":["export * from './getContent/index';\nexport * from './getNesting';\nexport * from './getEnumeration';\nexport * from './getIntlayer';\nexport * from './getDictionary';\nexport * from './getIntlayerAsync';\nexport * from './getTranslation';\nexport * from './getCondition';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../../src/interpreter/index.ts"],"sourcesContent":["export * from './getContent/index';\nexport * from './getNesting';\nexport * from './getEnumeration';\nexport * from './getIntlayer';\nexport * from './getDictionary';\nexport * from './getIntlayerAsync';\nexport * from './getTranslation';\nexport * from './getCondition';\nexport * from './getContent/index';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -1,21 +1,33 @@
1
+ import { getContent } from "../../interpreter/getContent/getContent.mjs";
1
2
  import {
2
3
  formatNodeType,
3
4
  NodeType
4
5
  } from "../../types/index.mjs";
5
6
  import { getMarkdownMetadata } from "./getMarkdownMetadata.mjs";
7
+ const awaitContent = async (content) => {
8
+ if (typeof content === "string" || typeof content === "object") {
9
+ return content;
10
+ }
11
+ if (typeof content === "function") {
12
+ return content();
13
+ }
14
+ if (typeof content.then === "function") {
15
+ return await content;
16
+ }
17
+ };
6
18
  const markdown = (content) => {
7
- const getMetadata = () => {
8
- if (typeof content === "string") {
9
- return getMarkdownMetadata(content);
10
- }
11
- if (typeof content === "function") {
12
- return () => getMarkdownMetadata(content());
13
- } else if (typeof content.then === "function") {
14
- return async () => getMarkdownMetadata(await content);
19
+ const metadata = async () => {
20
+ const awaitedContent = await awaitContent(content);
21
+ const flatContent = getContent(awaitedContent, {
22
+ dictionaryKey: "",
23
+ keyPath: []
24
+ });
25
+ if (typeof flatContent === "string") {
26
+ return getMarkdownMetadata(flatContent);
15
27
  }
16
28
  };
17
29
  return formatNodeType(NodeType.Markdown, content, {
18
- metadata: getMetadata()
30
+ metadata
19
31
  });
20
32
  };
21
33
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/transpiler/markdown/markdown.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getMarkdownMetadata } from './getMarkdownMetadata';\n\nexport type MarkdownContentConstructor<\n T extends Record<string, any> = {},\n Content = unknown,\n> = TypedNodeModel<NodeType.Markdown, Content, T>;\n\nexport type MarkdownContent<Content = unknown> = MarkdownContentConstructor<{\n metadata?: Record<string, any>;\n}>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * markdown('## Hello world!');\n * ```\n *\n */\nconst markdown = <Content = unknown>(content: Content): MarkdownContent => {\n const getMetadata = () => {\n if (typeof content === 'string') {\n return getMarkdownMetadata(content);\n }\n if (typeof content === 'function') {\n return () => getMarkdownMetadata(content());\n } else if (typeof (content as Promise<string>).then === 'function') {\n return async () =>\n getMarkdownMetadata(await (content as Promise<string>));\n }\n };\n\n return formatNodeType(NodeType.Markdown, content as string, {\n metadata: getMetadata(),\n });\n};\n\nexport { markdown as md };\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,2BAA2B;AAuBpC,MAAM,WAAW,CAAoB,YAAsC;AACzE,QAAM,cAAc,MAAM;AACxB,QAAI,OAAO,YAAY,UAAU;AAC/B,aAAO,oBAAoB,OAAO;AAAA,IACpC;AACA,QAAI,OAAO,YAAY,YAAY;AACjC,aAAO,MAAM,oBAAoB,QAAQ,CAAC;AAAA,IAC5C,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,aAAO,YACL,oBAAoB,MAAO,OAA2B;AAAA,IAC1D;AAAA,EACF;AAEA,SAAO,eAAe,SAAS,UAAU,SAAmB;AAAA,IAC1D,UAAU,YAAY;AAAA,EACxB,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/transpiler/markdown/markdown.ts"],"sourcesContent":["import { getContent } from '../../interpreter/getContent/getContent';\nimport {\n ContentNode,\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getMarkdownMetadata } from './getMarkdownMetadata';\n\nexport type MarkdownContentConstructor<\n T extends Record<string, any> = {},\n Content = unknown,\n> = TypedNodeModel<NodeType.Markdown, Content, T>;\n\nexport type MarkdownContent<Content = unknown> = MarkdownContentConstructor<{\n metadata?: Record<string, any>;\n}>;\n\nconst awaitContent = async (content: any) => {\n if (typeof content === 'string' || typeof content === 'object') {\n return content as any;\n }\n\n if (typeof content === 'function') {\n return content();\n }\n if (typeof content.then === 'function') {\n return await content;\n }\n};\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * markdown('## Hello world!');\n * ```\n *\n */\nconst markdown = <Content = unknown>(content: Content): MarkdownContent => {\n const metadata = async () => {\n const awaitedContent = await awaitContent(content);\n\n // @ts-ignore Type instantiation is excessively deep and possibly infinite.\n const flatContent = getContent(awaitedContent, {\n dictionaryKey: '',\n keyPath: [],\n });\n\n if (typeof flatContent === 'string') {\n return getMarkdownMetadata(flatContent);\n }\n };\n\n return formatNodeType(NodeType.Markdown, content as string, {\n metadata,\n });\n};\n\nexport { markdown as md };\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,2BAA2B;AAWpC,MAAM,eAAe,OAAO,YAAiB;AAC3C,MAAI,OAAO,YAAY,YAAY,OAAO,YAAY,UAAU;AAC9D,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,YAAY;AACjC,WAAO,QAAQ;AAAA,EACjB;AACA,MAAI,OAAO,QAAQ,SAAS,YAAY;AACtC,WAAO,MAAM;AAAA,EACf;AACF;AAcA,MAAM,WAAW,CAAoB,YAAsC;AACzE,QAAM,WAAW,YAAY;AAC3B,UAAM,iBAAiB,MAAM,aAAa,OAAO;AAGjD,UAAM,cAAc,WAAW,gBAAgB;AAAA,MAC7C,eAAe;AAAA,MACf,SAAS,CAAC;AAAA,IACZ,CAAC;AAED,QAAI,OAAO,gBAAgB,UAAU;AACnC,aAAO,oBAAoB,WAAW;AAAA,IACxC;AAAA,EACF;AAEA,SAAO,eAAe,SAAS,UAAU,SAAmB;AAAA,IAC1D;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"editDictionaryByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAY,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,eAAO,MAAM,uBAAuB,GAClC,mBAAmB,WAAW,EAC9B,SAAS,OAAO,EAAE,EAClB,UAAU,WAAW,KACpB,WAqGF,CAAC"}
1
+ {"version":3,"file":"editDictionaryByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/editDictionaryByKeyPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAY,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,eAAO,MAAM,uBAAuB,GAClC,mBAAmB,WAAW,EAC9B,SAAS,OAAO,EAAE,EAClB,UAAU,WAAW,KACpB,WAgHF,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from './deepTransform';
2
2
  export * from './plugins';
3
+ export * from './getContent';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/interpreter/getContent/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/interpreter/getContent/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
@@ -6,4 +6,5 @@ export * from './getDictionary';
6
6
  export * from './getIntlayerAsync';
7
7
  export * from './getTranslation';
8
8
  export * from './getCondition';
9
+ export * from './getContent/index';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/interpreter/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/interpreter/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/markdown/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EACR,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,MAAM,0BAA0B,CACpC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,EAClC,OAAO,GAAG,OAAO,IACf,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAElD,MAAM,MAAM,eAAe,CAAC,OAAO,GAAG,OAAO,IAAI,0BAA0B,CAAC;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,QAAQ,GAAI,OAAO,GAAG,OAAO,EAAE,SAAS,OAAO,KAAG,eAgBvD,CAAC;AAEF,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../../src/transpiler/markdown/markdown.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,QAAQ,EACR,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAG3B,MAAM,MAAM,0BAA0B,CACpC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,EAClC,OAAO,GAAG,OAAO,IACf,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAElD,MAAM,MAAM,eAAe,CAAC,OAAO,GAAG,OAAO,IAAI,0BAA0B,CAAC;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,CAAC,CAAC;AAeH;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,QAAQ,GAAI,OAAO,GAAG,OAAO,EAAE,SAAS,OAAO,KAAG,eAkBvD,CAAC;AAEF,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "5.3.6",
3
+ "version": "5.3.8",
4
4
  "private": false,
5
5
  "description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
6
6
  "keywords": [
@@ -71,9 +71,9 @@
71
71
  ],
72
72
  "dependencies": {
73
73
  "negotiator": "^1.0.0",
74
- "@intlayer/config": "5.3.6",
75
- "@intlayer/dictionaries-entry": "5.3.6",
76
- "@intlayer/api": "5.3.6"
74
+ "@intlayer/config": "5.3.8",
75
+ "@intlayer/dictionaries-entry": "5.3.8",
76
+ "@intlayer/api": "5.3.8"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/negotiator": "^0.6.3",
@@ -86,16 +86,16 @@
86
86
  "tsc-alias": "^1.8.10",
87
87
  "tsup": "^8.3.5",
88
88
  "typescript": "^5.7.3",
89
- "@utils/eslint-config": "1.0.4",
90
89
  "@utils/ts-config": "1.0.4",
90
+ "@utils/ts-config-types": "1.0.4",
91
91
  "@utils/tsup-config": "1.0.4",
92
- "@utils/ts-config-types": "1.0.4"
92
+ "@utils/eslint-config": "1.0.4"
93
93
  },
94
94
  "peerDependencies": {
95
- "@intlayer/api": "5.3.6",
96
- "@intlayer/dictionaries-entry": "5.3.6",
97
- "intlayer": "5.3.6",
98
- "@intlayer/config": "5.3.6"
95
+ "@intlayer/config": "5.3.8",
96
+ "@intlayer/dictionaries-entry": "5.3.8",
97
+ "@intlayer/api": "5.3.8",
98
+ "intlayer": "5.3.8"
99
99
  },
100
100
  "engines": {
101
101
  "node": ">=14.18"