@intlayer/core 5.3.1 → 5.3.2
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.
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +2 -14
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +2 -0
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +52 -3
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getInsertion.cjs +29 -0
- package/dist/cjs/interpreter/getInsertion.cjs.map +1 -0
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs +57 -0
- package/dist/cjs/transpiler/file/file.cjs.map +1 -0
- package/dist/cjs/transpiler/file/index.cjs +23 -0
- package/dist/cjs/transpiler/file/index.cjs.map +1 -0
- package/dist/cjs/transpiler/index.cjs +2 -0
- package/dist/cjs/transpiler/index.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +34 -0
- package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -0
- package/dist/cjs/transpiler/insertion/index.cjs +25 -0
- package/dist/cjs/transpiler/insertion/index.cjs.map +1 -0
- package/dist/cjs/transpiler/insertion/insertion.cjs +54 -0
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -0
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs +30 -26
- package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/index.cjs +1 -3
- package/dist/cjs/transpiler/translation/index.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/types/dictionary.cjs.map +1 -1
- package/dist/cjs/types/index.cjs +3 -1
- package/dist/cjs/types/index.cjs.map +1 -1
- package/dist/cjs/types/keyPath.cjs.map +1 -1
- package/dist/cjs/types/nodeType.cjs +2 -0
- package/dist/cjs/types/nodeType.cjs.map +1 -1
- package/dist/cjs/{transpiler/translation/types.cjs → types/translation.cjs} +3 -3
- package/dist/cjs/types/translation.cjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getNodeType.mjs +2 -14
- package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/getContent.mjs +4 -1
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +51 -3
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getInsertion.mjs +5 -0
- package/dist/esm/interpreter/getInsertion.mjs.map +1 -0
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/transpiler/file/file.mjs +40 -0
- package/dist/esm/transpiler/file/file.mjs.map +1 -0
- package/dist/esm/transpiler/file/index.mjs +2 -0
- package/dist/esm/transpiler/file/index.mjs.map +1 -0
- package/dist/esm/transpiler/index.mjs +1 -0
- package/dist/esm/transpiler/index.mjs.map +1 -1
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs +10 -0
- package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -0
- package/dist/esm/transpiler/insertion/index.mjs +3 -0
- package/dist/esm/transpiler/insertion/index.mjs.map +1 -0
- package/dist/esm/transpiler/insertion/insertion.mjs +33 -0
- package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -0
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs +30 -26
- package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs +1 -1
- package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
- package/dist/esm/transpiler/translation/index.mjs +0 -1
- package/dist/esm/transpiler/translation/index.mjs.map +1 -1
- package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/types/nodeType.mjs +2 -0
- package/dist/esm/types/nodeType.mjs.map +1 -1
- package/dist/esm/types/translation.mjs +1 -0
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +1 -1
- package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +12 -0
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getInsertion.d.ts +16 -0
- package/dist/types/interpreter/getInsertion.d.ts.map +1 -0
- package/dist/types/interpreter/getTranslation.d.ts +1 -1
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/transpiler/condition/condition.d.ts +1 -1
- package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/file/file.d.ts +23 -0
- package/dist/types/transpiler/file/file.d.ts.map +1 -0
- package/dist/types/transpiler/file/index.d.ts +2 -0
- package/dist/types/transpiler/file/index.d.ts.map +1 -0
- package/dist/types/transpiler/index.d.ts +1 -0
- package/dist/types/transpiler/index.d.ts.map +1 -1
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts +2 -0
- package/dist/types/transpiler/insertion/getInsertionValues.d.ts.map +1 -0
- package/dist/types/transpiler/insertion/index.d.ts +3 -0
- package/dist/types/transpiler/insertion/index.d.ts.map +1 -0
- package/dist/types/transpiler/insertion/insertion.d.ts +19 -0
- package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -0
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts +1 -1
- package/dist/types/transpiler/markdown/getMarkdownMetadata.d.ts.map +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts +1 -1
- package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
- package/dist/types/transpiler/translation/index.d.ts +0 -1
- package/dist/types/transpiler/translation/index.d.ts.map +1 -1
- package/dist/types/transpiler/translation/translation.d.ts +8 -3
- package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
- package/dist/types/types/dictionary.d.ts +8 -2
- package/dist/types/types/dictionary.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/keyPath.d.ts +9 -1
- package/dist/types/types/keyPath.d.ts.map +1 -1
- package/dist/types/types/nodeType.d.ts +10 -4
- package/dist/types/types/nodeType.d.ts.map +1 -1
- package/dist/types/{transpiler/translation/types.d.ts → types/translation.d.ts} +1 -3
- package/dist/types/types/translation.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/cjs/transpiler/translation/types.cjs.map +0 -1
- package/dist/esm/transpiler/translation/types.mjs +0 -1
- package/dist/types/transpiler/translation/types.d.ts.map +0 -1
- /package/dist/esm/{transpiler/translation/types.mjs.map → types/translation.mjs.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/markdown/getMarkdownMetadata.ts"],"sourcesContent":["const parseToObject = <T = any>(input: string): T | null => {\n // Normalize different bracket types and keys/values\n let normalizedInput = input\n .trim()\n .replace(/^\\[/, '[') // Keep array brackets\n .replace(/^\\{/, '{') // Keep object brackets\n .replace(/\\]$/, ']') // Keep array brackets\n .replace(/\\}$/, '}') // Keep object brackets\n .replace(/([\\w\\d_]+)\\s*:/g, '\"$1\":') // Ensure JSON-valid keys (e.g., key: -> \"key\":)\n .replace(/:\\s*([a-zA-Z_][\\w\\d_]*)/g, ': \"$1\"'); // Handle unquoted string values\n\n // Fix arrays with unquoted items (e.g., [content, anotherContent])\n normalizedInput = normalizedInput.replace(\n /\\[([^\\[\\]]+?)\\]/g,\n (_match, arrayContent) => {\n const newContent = (arrayContent as string)\n .split(',')\n .map((item) => {\n const trimmed = item.trim();\n // If already quoted or is a valid number, return as is.\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n !isNaN(Number(trimmed))\n ) {\n return trimmed;\n }\n return `\"${trimmed}\"`;\n })\n .join(', ');\n return `[${newContent}]`;\n }\n );\n\n // Parse the string into an object\n return JSON.parse(normalizedInput) as T;\n};\n\nexport const getMarkdownMetadata = (markdown: string): Record<string, any> => {\n const lines = markdown.split(/\\r?\\n/);\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/markdown/getMarkdownMetadata.ts"],"sourcesContent":["const parseToObject = <T = any>(input: string): T | null => {\n // Normalize different bracket types and keys/values\n let normalizedInput = input\n .trim()\n .replace(/^\\[/, '[') // Keep array brackets\n .replace(/^\\{/, '{') // Keep object brackets\n .replace(/\\]$/, ']') // Keep array brackets\n .replace(/\\}$/, '}') // Keep object brackets\n .replace(/([\\w\\d_]+)\\s*:/g, '\"$1\":') // Ensure JSON-valid keys (e.g., key: -> \"key\":)\n .replace(/:\\s*([a-zA-Z_][\\w\\d_]*)/g, ': \"$1\"'); // Handle unquoted string values\n\n // Fix arrays with unquoted items (e.g., [content, anotherContent])\n normalizedInput = normalizedInput.replace(\n /\\[([^\\[\\]]+?)\\]/g,\n (_match, arrayContent) => {\n const newContent = (arrayContent as string)\n .split(',')\n .map((item) => {\n const trimmed = item.trim();\n // If already quoted or is a valid number, return as is.\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n !isNaN(Number(trimmed))\n ) {\n return trimmed;\n }\n return `\"${trimmed}\"`;\n })\n .join(', ');\n return `[${newContent}]`;\n }\n );\n\n // Parse the string into an object\n return JSON.parse(normalizedInput) as T;\n};\n\nexport const getMarkdownMetadata = (\n markdown: string\n): Record<string, any> | undefined => {\n try {\n const lines = markdown.split(/\\r?\\n/);\n\n // Check if the very first non-empty line is the metadata start delimiter.\n const firstNonEmptyLine = lines.find((line) => line.trim() !== '');\n\n if (!firstNonEmptyLine || firstNonEmptyLine.trim() !== '---') {\n return {};\n }\n\n const metadata: Record<string, any> = {};\n let inMetadataBlock = false;\n\n for (const line of lines) {\n const trimmedLine = line.trim();\n\n // Toggle metadata block on encountering the delimiter.\n if (trimmedLine === '---') {\n if (!inMetadataBlock) {\n // Begin metadata block.\n inMetadataBlock = true;\n continue;\n } else {\n // End of metadata block; stop processing.\n break;\n }\n }\n\n // If we're inside the metadata block, parse key: value pairs.\n if (inMetadataBlock) {\n const match = line.match(/^([^:]+)\\s*:\\s*(.*)$/);\n if (match) {\n const key = match[1].trim();\n const value = match[2].trim();\n try {\n metadata[key] = parseToObject(value);\n } catch (e) {\n metadata[key] = value;\n }\n }\n }\n }\n\n return metadata;\n } catch (e) {\n return undefined;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,gBAAgB,CAAU,UAA4B;AAE1D,MAAI,kBAAkB,MACnB,KAAK,EACL,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,mBAAmB,OAAO,EAClC,QAAQ,4BAA4B,QAAQ;AAG/C,oBAAkB,gBAAgB;AAAA,IAChC;AAAA,IACA,CAAC,QAAQ,iBAAiB;AACxB,YAAM,aAAc,aACjB,MAAM,GAAG,EACT,IAAI,CAAC,SAAS;AACb,cAAM,UAAU,KAAK,KAAK;AAE1B,YACG,QAAQ,WAAW,GAAG,KAAK,QAAQ,SAAS,GAAG,KAChD,CAAC,MAAM,OAAO,OAAO,CAAC,GACtB;AACA,iBAAO;AAAA,QACT;AACA,eAAO,IAAI,OAAO;AAAA,MACpB,CAAC,EACA,KAAK,IAAI;AACZ,aAAO,IAAI,UAAU;AAAA,IACvB;AAAA,EACF;AAGA,SAAO,KAAK,MAAM,eAAe;AACnC;AAEO,MAAM,sBAAsB,CACjC,aACoC;AACpC,MAAI;AACF,UAAM,QAAQ,SAAS,MAAM,OAAO;AAGpC,UAAM,oBAAoB,MAAM,KAAK,CAAC,SAAS,KAAK,KAAK,MAAM,EAAE;AAEjE,QAAI,CAAC,qBAAqB,kBAAkB,KAAK,MAAM,OAAO;AAC5D,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,WAAgC,CAAC;AACvC,QAAI,kBAAkB;AAEtB,eAAW,QAAQ,OAAO;AACxB,YAAM,cAAc,KAAK,KAAK;AAG9B,UAAI,gBAAgB,OAAO;AACzB,YAAI,CAAC,iBAAiB;AAEpB,4BAAkB;AAClB;AAAA,QACF,OAAO;AAEL;AAAA,QACF;AAAA,MACF;AAGA,UAAI,iBAAiB;AACnB,cAAM,QAAQ,KAAK,MAAM,sBAAsB;AAC/C,YAAI,OAAO;AACT,gBAAM,MAAM,MAAM,CAAC,EAAE,KAAK;AAC1B,gBAAM,QAAQ,MAAM,CAAC,EAAE,KAAK;AAC5B,cAAI;AACF,qBAAS,GAAG,IAAI,cAAc,KAAK;AAAA,UACrC,SAAS,GAAG;AACV,qBAAS,GAAG,IAAI;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -30,7 +30,7 @@ const markdown = (content) => {
|
|
|
30
30
|
}
|
|
31
31
|
if (typeof content === "function") {
|
|
32
32
|
return () => (0, import_getMarkdownMetadata.getMarkdownMetadata)(content());
|
|
33
|
-
} else {
|
|
33
|
+
} else if (typeof content.then === "function") {
|
|
34
34
|
return async () => (0, import_getMarkdownMetadata.getMarkdownMetadata)(await content);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
@@ -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 MarkdownContentState = string;\n\nexport type MarkdownContent = TypedNodeModel<\n NodeType.Markdown,\n MarkdownContentState\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 =
|
|
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 MarkdownContentState = string;\n\nexport type MarkdownContent = TypedNodeModel<\n NodeType.Markdown,\n MarkdownContentState\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;AAqBpC,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":[]}
|
|
@@ -16,10 +16,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var translation_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(translation_exports);
|
|
18
18
|
__reExport(translation_exports, require('./translation.cjs'), module.exports);
|
|
19
|
-
__reExport(translation_exports, require('./types.cjs'), module.exports);
|
|
20
19
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21
20
|
0 && (module.exports = {
|
|
22
|
-
...require('./translation.cjs')
|
|
23
|
-
...require('./types.cjs')
|
|
21
|
+
...require('./translation.cjs')
|
|
24
22
|
});
|
|
25
23
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/translation/index.ts"],"sourcesContent":["export * from './translation';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/translation/index.ts"],"sourcesContent":["export * from './translation';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,0BAAd;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/translation/translation.ts"],"sourcesContent":["import { formatNodeType, NodeType } from '../../types/index';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/translation/translation.ts"],"sourcesContent":["import type { LanguageContent } from 'intlayer';\nimport { formatNodeType, NodeType, TypedNodeModel } from '../../types/index';\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends LanguageContent<Content> = LanguageContent<Content>,\n> = TypedNodeModel<NodeType.Translation, RecordContent>;\n\n/**\n *\n * Function intended to be used to build intlayer dictionaries.\n *\n * Get the content of a translation based on the locale.\n *\n * Usage:\n *\n * ```ts\n * translation<string>({\n * \"en\": \"Hello\",\n * \"fr\": \"Bonjour\",\n * // ... any other available locale\n * })\n * ```\n *\n * Using TypeScript:\n * - this function require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nconst translation = <\n Content = unknown,\n ContentRecord extends LanguageContent<Content> = LanguageContent<Content>,\n>(\n content: ContentRecord\n) =>\n formatNodeType(NodeType.Translation, content) satisfies TranslationContent<\n Content,\n ContentRecord\n >;\n\nexport { translation as t };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyD;AA2BzD,MAAM,cAAc,CAIlB,gBAEA,6BAAe,sBAAS,aAAa,OAAO;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/types/dictionary.ts"],"sourcesContent":["// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { ConditionContent } from '../transpiler/condition';\nimport type { EnumerationContent } from '../transpiler/enumeration';\nimport type { FileContent } from '../transpiler/file';\nimport type { InsertionContent } from '../transpiler/insertion';\nimport type { MarkdownContent } from '../transpiler/markdown';\nimport type { NestedContent } from '../transpiler/nesting';\nimport type { TranslationContent } from '../transpiler/translation';\n\n/**\n * Provides a fallback to string type if the generic type T is undefined,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<undefined> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends undefined ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\ntype BaseNode = number | string | boolean | null | undefined;\n\nexport type TypedNode<NodeType = undefined> =\n | TranslationContent<NodeType>\n | EnumerationContent<NodeType>\n | ConditionContent<NodeType>\n | InsertionContent<NodeType>\n | MarkdownContent\n | NestedContent<DictionaryKeys>\n | FileContent;\n\ntype FetchableContentNode<NodeType> = (\n args?: any\n) => ContentNode<NodeType> | Promise<ContentNode<NodeType>>;\n\nexport type ContentNode<\n T = undefined,\n FetchableNode = false,\n NodeType = T extends undefined ? BaseNode : T,\n> =\n | NodeType\n | TypedNode<NodeType>\n | ((args?: any) => ContentNode<NodeType>)\n | (FetchableNode extends true ? FetchableContentNode<NodeType> : undefined);\n\n// Utility types (unchanged)\ntype IsArray<T> = T extends any[] ? true : false;\n\ntype ReplaceContentValueArray<T, FetchableNode> = T extends (infer U)[]\n ? // Allow either a *single* typed node returning the entire array\n // or an array of typed nodes (or scalar nodes).\n ContentNode<T, FetchableNode> | ReplaceContentValue<U, FetchableNode>[]\n : never;\n\ntype ReplaceContentValueObject<T, FetchableNode> = {\n [K in keyof T]: ReplaceContentValue<T[K], FetchableNode>;\n};\n\n// Modified: allow a full ContentNode wrapper OR an object shape when T is an object\ntype ReplaceContentValue<\n NodeType,\n FetchableNode = true,\n> = NodeType extends object\n ? IsArray<NodeType> extends true\n ? ReplaceContentValueArray<NodeType, FetchableNode>\n :\n | ContentNode<NodeType, FetchableNode>\n | ReplaceContentValueObject<NodeType, FetchableNode>\n : ContentNode<NodeType, FetchableNode>;\n\nexport type Dictionary<ContentType = undefined, FetchableNode = false> = {\n $schema?: string;\n key: string;\n title?: string;\n description?: string;\n availableVersions?: string[];\n version?: string;\n filePath?: string;\n tags?: string[];\n content: ContentType extends undefined // Applying the generic to replace ContentValue with Replacement\n ? any\n : ReplaceContentValue<ContentType, FetchableNode> | ContentType;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/cjs/types/index.cjs
CHANGED
|
@@ -18,10 +18,12 @@ module.exports = __toCommonJS(types_exports);
|
|
|
18
18
|
__reExport(types_exports, require('./dictionary.cjs'), module.exports);
|
|
19
19
|
__reExport(types_exports, require('./nodeType.cjs'), module.exports);
|
|
20
20
|
__reExport(types_exports, require('./keyPath.cjs'), module.exports);
|
|
21
|
+
__reExport(types_exports, require('./translation.cjs'), module.exports);
|
|
21
22
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
23
|
0 && (module.exports = {
|
|
23
24
|
...require('./dictionary.cjs'),
|
|
24
25
|
...require('./nodeType.cjs'),
|
|
25
|
-
...require('./keyPath.cjs')
|
|
26
|
+
...require('./keyPath.cjs'),
|
|
27
|
+
...require('./translation.cjs')
|
|
26
28
|
});
|
|
27
29
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export * from './dictionary';\nexport * from './nodeType';\nexport * from './keyPath';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,yBAAd;AACA,0BAAc,uBADd;AAEA,0BAAc,sBAFd;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export * from './dictionary';\nexport * from './nodeType';\nexport * from './keyPath';\nexport * from './translation';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,yBAAd;AACA,0BAAc,uBADd;AAEA,0BAAc,sBAFd;AAGA,0BAAc,0BAHd;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/keyPath.ts"],"sourcesContent":["import type { NodeType } from './nodeType';\n\nexport type ObjectNode = {\n type: NodeType.Object;\n key: string;\n};\n\nexport type ArrayNode = {\n type: NodeType.Array;\n key: number;\n};\n\nexport type EnumerationNode = {\n type: NodeType.Enumeration;\n key: string;\n};\n\nexport type TranslationNode = {\n type: NodeType.Translation;\n key: string;\n};\n\nexport type ConditionNode = {\n type: NodeType.Condition;\n key: string;\n};\n\nexport type MarkdownNode = {\n type: NodeType.Markdown;\n key?: undefined;\n};\n\nexport type ReactNode = {\n type: NodeType.ReactNode;\n key?: undefined;\n};\n\nexport type NestedNode = {\n type: NodeType.Nested;\n key?: undefined;\n};\n\nexport type KeyPath =\n | ObjectNode\n | ArrayNode\n | TranslationNode\n | EnumerationNode\n | MarkdownNode\n | ReactNode\n | ConditionNode\n | NestedNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/keyPath.ts"],"sourcesContent":["import type { NodeType } from './nodeType';\n\nexport type ObjectNode = {\n type: NodeType.Object;\n key: string;\n};\n\nexport type ArrayNode = {\n type: NodeType.Array;\n key: number;\n};\n\nexport type EnumerationNode = {\n type: NodeType.Enumeration;\n key: string;\n};\n\nexport type TranslationNode = {\n type: NodeType.Translation;\n key: string;\n};\n\nexport type ConditionNode = {\n type: NodeType.Condition;\n key: string;\n};\n\nexport type InsertionNode = {\n type: NodeType.Insertion;\n key?: undefined;\n};\n\nexport type MarkdownNode = {\n type: NodeType.Markdown;\n key?: undefined;\n};\n\nexport type ReactNode = {\n type: NodeType.ReactNode;\n key?: undefined;\n};\n\nexport type NestedNode = {\n type: NodeType.Nested;\n key?: undefined;\n};\n\nexport type FileNode = {\n type: NodeType.File;\n key?: undefined;\n};\n\nexport type KeyPath =\n | ObjectNode\n | ArrayNode\n | TranslationNode\n | EnumerationNode\n | InsertionNode\n | MarkdownNode\n | ReactNode\n | ConditionNode\n | NestedNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -26,6 +26,8 @@ var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
|
26
26
|
NodeType2["Translation"] = "translation";
|
|
27
27
|
NodeType2["Enumeration"] = "enumeration";
|
|
28
28
|
NodeType2["Condition"] = "condition";
|
|
29
|
+
NodeType2["Insertion"] = "insertion";
|
|
30
|
+
NodeType2["File"] = "file";
|
|
29
31
|
NodeType2["Object"] = "object";
|
|
30
32
|
NodeType2["Array"] = "array";
|
|
31
33
|
NodeType2["Nested"] = "nested";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/nodeType.ts"],"sourcesContent":["export enum NodeType {\n Translation = 'translation',\n Enumeration = 'enumeration',\n Condition = 'condition',\n Object = 'object',\n Array = 'array',\n Nested = 'nested',\n ReactNode = 'reactNode',\n Markdown = 'markdown',\n Text = 'text',\n Number = 'number',\n Boolean = 'boolean',\n Unknown = 'unknown',\n}\n\nexport type TypedNodeModel
|
|
1
|
+
{"version":3,"sources":["../../../src/types/nodeType.ts"],"sourcesContent":["export enum NodeType {\n Translation = 'translation',\n Enumeration = 'enumeration',\n Condition = 'condition',\n Insertion = 'insertion',\n File = 'file',\n Object = 'object',\n Array = 'array',\n Nested = 'nested',\n ReactNode = 'reactNode',\n Markdown = 'markdown',\n Text = 'text',\n Number = 'number',\n Boolean = 'boolean',\n Unknown = 'unknown',\n}\n\ntype AdditionalAttributesType = {\n [key: string]: any;\n};\n\nexport type TypedNodeModel<\n T extends NodeType,\n Content,\n AdditionalAttributes extends AdditionalAttributesType = {},\n> = {\n nodeType: T | `${T}`;\n} & {\n [K in T]: Content;\n} & AdditionalAttributes;\n\nexport const formatNodeType = <\n T extends NodeType,\n Content = any,\n AdditionalAttributes extends AdditionalAttributesType = {},\n>(\n nodeType: T | `${T}`,\n content: Content,\n additionalAttributes?: { [key: string]: any }\n) =>\n ({\n ...additionalAttributes,\n nodeType,\n [nodeType]: content,\n }) as TypedNodeModel<T, Content, AdditionalAttributes>;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,UAAA,iBAAc;AACd,EAAAA,UAAA,iBAAc;AACd,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,WAAQ;AACR,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,UAAO;AACP,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,aAAU;AACV,EAAAA,UAAA,aAAU;AAdA,SAAAA;AAAA,GAAA;AA+BL,MAAM,iBAAiB,CAK5B,UACA,SACA,0BAEC;AAAA,EACC,GAAG;AAAA,EACH;AAAA,EACA,CAAC,QAAQ,GAAG;AACd;","names":["NodeType"]}
|
|
@@ -12,6 +12,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
module.exports = __toCommonJS(
|
|
17
|
-
//# sourceMappingURL=
|
|
15
|
+
var translation_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(translation_exports);
|
|
17
|
+
//# sourceMappingURL=translation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/translation.ts"],"sourcesContent":["/** @ts-nocheck */\n\nimport type { LocalesValues } from '@intlayer/config/client';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * Record of locales and content\n *\n * const myVar1: TranslationContentState<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: TranslationContentState<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type TranslationContentState<Content = unknown> = {\n [locale in LocalesValues]?: Content;\n};\n\nexport type LanguageContent<Content = unknown> =\n keyof IConfigLocales<unknown> extends never\n ? TranslationContentState<Content> // Fall including all locales as optional\n : IConfigLocales<Content>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -12,7 +12,7 @@ const getNodeChildren = (section) => {
|
|
|
12
12
|
if (typeof section?.nodeType === "string") {
|
|
13
13
|
const typedNode = section;
|
|
14
14
|
const content = typedNode[typedNode.nodeType];
|
|
15
|
-
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition) {
|
|
15
|
+
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion || typedNode.nodeType === NodeType.File) {
|
|
16
16
|
const firstKey = Object.keys(content)[0];
|
|
17
17
|
return content[firstKey];
|
|
18
18
|
}
|
|
@@ -1 +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,SAA2C,gBAAgB;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,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,
|
|
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 typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.File\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,SAA2C,gBAAgB;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,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,MAChC;AACA,YAAM,WAAW,OAAO,KAAK,OAAO,EAAE,CAAC;AACvC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,QAAI,UAAU,aAAa,SAAS,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":[]}
|
|
@@ -4,20 +4,8 @@ const getNodeType = (content) => {
|
|
|
4
4
|
if (typeof content === "string") {
|
|
5
5
|
return NodeType.Text;
|
|
6
6
|
}
|
|
7
|
-
if (content?.nodeType ===
|
|
8
|
-
return
|
|
9
|
-
}
|
|
10
|
-
if (content?.nodeType === NodeType.Enumeration) {
|
|
11
|
-
return NodeType.Enumeration;
|
|
12
|
-
}
|
|
13
|
-
if (content?.nodeType === NodeType.Condition) {
|
|
14
|
-
return NodeType.Condition;
|
|
15
|
-
}
|
|
16
|
-
if (content?.nodeType === NodeType.Markdown) {
|
|
17
|
-
return NodeType.Markdown;
|
|
18
|
-
}
|
|
19
|
-
if (content?.nodeType === NodeType.Nested) {
|
|
20
|
-
return NodeType.Nested;
|
|
7
|
+
if (typeof content?.nodeType === "string") {
|
|
8
|
+
return content.nodeType;
|
|
21
9
|
}
|
|
22
10
|
if (Array.isArray(content)) {
|
|
23
11
|
return NodeType.Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeType.ts"],"sourcesContent":["import { NodeType, type TypedNode } 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 (typeof (content as TypedNode)?.nodeType === 'string') {\n return (content as TypedNode).nodeType as NodeType;\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,SAAS,gBAAgC;AAEzC,SAAS,sBAAsB;AAExB,MAAM,cAAc,CAAC,YAAmC;AAC7D,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,WAAQ,QAAsB;AAAA,EAChC;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,eAAe,OAAO,GAAG;AAC3B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO,SAAS;AAAA,EAClB;AAEA,MAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,WAAO,SAAS;AAAA,EAClB;AAEA,SAAO,SAAS;AAClB;","names":[]}
|
|
@@ -4,14 +4,17 @@ import {
|
|
|
4
4
|
translationPlugin,
|
|
5
5
|
enumerationPlugin,
|
|
6
6
|
conditionPlugin,
|
|
7
|
-
nestedPlugin
|
|
7
|
+
nestedPlugin,
|
|
8
|
+
insertionPlugin
|
|
8
9
|
} from "./plugins.mjs";
|
|
9
10
|
const getContent = (node, nodeProps, locale = configuration.internationalization.defaultLocale) => {
|
|
10
11
|
const plugins = [
|
|
12
|
+
insertionPlugin,
|
|
11
13
|
translationPlugin(locale),
|
|
12
14
|
enumerationPlugin,
|
|
13
15
|
conditionPlugin,
|
|
14
16
|
nestedPlugin,
|
|
17
|
+
// filePlugin,
|
|
15
18
|
...nodeProps.plugins ?? []
|
|
16
19
|
];
|
|
17
20
|
return deepTransformNode(node, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './plugins';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAG1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/getContent.ts"],"sourcesContent":["import { type Locales, type LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport type { ContentNode } from '../../types';\nimport { deepTransformNode } from './deepTransform';\nimport {\n translationPlugin,\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n insertionPlugin,\n // filePlugin,\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n} from './plugins';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getContent = <\n T extends ContentNode,\n L extends LocalesValues = Locales,\n>(\n node: T,\n nodeProps: NodeProps,\n locale: L = configuration.internationalization.defaultLocale as L\n) => {\n const plugins: Plugins[] = [\n insertionPlugin,\n translationPlugin(locale),\n enumerationPlugin,\n conditionPlugin,\n nestedPlugin,\n // filePlugin,\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAG1B,SAAS,yBAAyB;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAQA,MAAM,aAAa,CAIxB,MACA,WACA,SAAY,cAAc,qBAAqB,kBAC5C;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA,kBAAkB,MAAM;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,SAAO,kBAAkB,MAAM;AAAA,IAC7B,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -3,10 +3,12 @@ import { getCondition } from "../getCondition.mjs";
|
|
|
3
3
|
import { getEnumeration } from "../getEnumeration.mjs";
|
|
4
4
|
import { getNesting } from "../getNesting.mjs";
|
|
5
5
|
import { getTranslation } from "../getTranslation.mjs";
|
|
6
|
+
import { getInsertion } from "../getInsertion.mjs";
|
|
6
7
|
const translationPlugin = (locale) => ({
|
|
8
|
+
id: "translation-plugin",
|
|
7
9
|
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
|
|
8
10
|
transform: (node, props, deepTransformNode) => {
|
|
9
|
-
const result = structuredClone(node.
|
|
11
|
+
const result = structuredClone(node[NodeType.Translation]);
|
|
10
12
|
for (const key in result) {
|
|
11
13
|
const childProps = {
|
|
12
14
|
...props,
|
|
@@ -25,9 +27,10 @@ const translationPlugin = (locale) => ({
|
|
|
25
27
|
}
|
|
26
28
|
});
|
|
27
29
|
const enumerationPlugin = {
|
|
30
|
+
id: "enumeration-plugin",
|
|
28
31
|
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Enumeration,
|
|
29
32
|
transform: (node, props, deepTransformNode) => {
|
|
30
|
-
const result = structuredClone(node.
|
|
33
|
+
const result = structuredClone(node[NodeType.Enumeration]);
|
|
31
34
|
for (const key in result) {
|
|
32
35
|
const child = result[key];
|
|
33
36
|
const childProps = {
|
|
@@ -47,9 +50,10 @@ const enumerationPlugin = {
|
|
|
47
50
|
}
|
|
48
51
|
};
|
|
49
52
|
const conditionPlugin = {
|
|
53
|
+
id: "condition-plugin",
|
|
50
54
|
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Condition,
|
|
51
55
|
transform: (node, props, deepTransformNode) => {
|
|
52
|
-
const result = structuredClone(node.
|
|
56
|
+
const result = structuredClone(node[NodeType.Condition]);
|
|
53
57
|
for (const key in result) {
|
|
54
58
|
const child = result[key];
|
|
55
59
|
const childProps = {
|
|
@@ -68,13 +72,57 @@ const conditionPlugin = {
|
|
|
68
72
|
return (value) => getCondition(result, value);
|
|
69
73
|
}
|
|
70
74
|
};
|
|
75
|
+
const insertionPlugin = {
|
|
76
|
+
id: "insertion-plugin",
|
|
77
|
+
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Insertion,
|
|
78
|
+
transform: (node, props, deepTransformNode) => {
|
|
79
|
+
const newKeyPath = [
|
|
80
|
+
...props.keyPath,
|
|
81
|
+
{
|
|
82
|
+
type: NodeType.Insertion
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
const children = node[NodeType.Insertion];
|
|
86
|
+
const insertionStringPlugin = {
|
|
87
|
+
id: "insertion-string-plugin",
|
|
88
|
+
canHandle: (node2) => typeof node2 === "string",
|
|
89
|
+
transform: (node2, subProps, deepTransformNode2) => {
|
|
90
|
+
const transformedResult = deepTransformNode2(node2, {
|
|
91
|
+
...subProps,
|
|
92
|
+
children: node2,
|
|
93
|
+
plugins: [
|
|
94
|
+
...(props.plugins ?? []).filter(
|
|
95
|
+
(plugin) => plugin.id !== "intlayer-node-plugin"
|
|
96
|
+
)
|
|
97
|
+
]
|
|
98
|
+
});
|
|
99
|
+
return (values) => {
|
|
100
|
+
const children2 = getInsertion(transformedResult, values);
|
|
101
|
+
return deepTransformNode2(children2, {
|
|
102
|
+
...subProps,
|
|
103
|
+
plugins: props.plugins,
|
|
104
|
+
children: children2
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return deepTransformNode(children, {
|
|
110
|
+
...props,
|
|
111
|
+
children,
|
|
112
|
+
keyPath: newKeyPath,
|
|
113
|
+
plugins: [insertionStringPlugin, ...props.plugins ?? []]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
};
|
|
71
117
|
const nestedPlugin = {
|
|
118
|
+
id: "nested-plugin",
|
|
72
119
|
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Nested,
|
|
73
120
|
transform: (node, props) => getNesting(node.nested.dictionaryKey, node.nested.path, props)
|
|
74
121
|
};
|
|
75
122
|
export {
|
|
76
123
|
conditionPlugin,
|
|
77
124
|
enumerationPlugin,
|
|
125
|
+
insertionPlugin,
|
|
78
126
|
nestedPlugin,
|
|
79
127
|
translationPlugin
|
|
80
128
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\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 children: 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 children: 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 children: 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 children?: 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":"AAOA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAgC,kBAAkB;AAClD,SAAS,sBAAsB;AAqCxB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;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,UAAU,OAAO,GAAqC;AAAA,QACtD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,WAAO,eAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;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,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,aAAqB,eAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;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,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,UAAmB,aAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,UAC/B,WAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n NestedContent,\n TranslationContent,\n InsertionContent,\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';\nimport { getInsertion } from '../getInsertion';\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 id: string;\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 id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: 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 id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.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 children: 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 id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: 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 * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string>) => DeepTransformContent<I, S>\n : (data: Record<string, string>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: {\n [K in InsertionContent['fields'][number]]: string;\n }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\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 id: 'nested-plugin',\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// * FILE PLUGIN\n// * --------------------------------------------- */\n\n// export type FileCond<T> = T extends {\n// nodeType: NodeType | string;\n// [NodeType.File]: string;\n// content?: string;\n// }\n// ? string\n// : never;\n\n// /** File plugin. Replaces node with the result of `getNesting`. */\n// export const filePlugin: Plugins = {\n// id: 'file-plugin',\n// canHandle: (node) =>\n// typeof node === 'object' && node?.nodeType === NodeType.File,\n// transform: (node: FileContent, props, deepTransform) =>\n// deepTransform(node.content, {\n// ...props,\n// children: node.content,\n// }),\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 children?: 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 insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\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 insertion: true;\n nested: true;\n // file: 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":"AAQA,SAA4C,gBAAgB;AAC5D,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAgC,kBAAkB;AAClD,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAsCtB,MAAM,oBAAoB,CAAC,YAAoC;AAAA,EACpE,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,SAAS,WAAW,CAAC;AAEzD,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU,OAAO,GAAqC;AAAA,QACtD,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AACA,WAAO,eAAe,QAAQ,MAAM;AAAA,EACtC;AACF;AAmBO,MAAM,oBAA6B;AAAA,EACxC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAA0B,OAAO,sBAAsB;AACjE,UAAM,SAAS,gBAAgB,KAAK,SAAS,WAAW,CAAC;AAEzD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAAqC;AAC1D,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,aAAa,IAAI;AAAA,QACpC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,aAAqB,eAAe,QAAQ,QAAQ;AAAA,EAC9D;AACF;AAmBO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,SAAS,gBAAgB,KAAK,SAAS,SAAS,CAAC;AAEvD,eAAW,OAAO,QAAQ;AACxB,YAAM,QAAQ,OAAO,GAA0B;AAC/C,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,SAAS,WAAW,IAAI;AAAA,QAClC;AAAA,MACF;AACA,aAAO,GAAqC,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,CAAC,UAAmB,aAAa,QAAQ,KAAK;AAAA,EACvD;AACF;AAgBO,MAAM,kBAA2B;AAAA,EACtC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAwB,OAAO,sBAAsB;AAC/D,UAAM,aAAwB;AAAA,MAC5B,GAAG,MAAM;AAAA,MACT;AAAA,QACE,MAAM,SAAS;AAAA,MACjB;AAAA,IACF;AAEA,UAAM,WAAW,KAAK,SAAS,SAAS;AAGxC,UAAM,wBAAiC;AAAA,MACrC,IAAI;AAAA,MACJ,WAAW,CAACA,UAAS,OAAOA,UAAS;AAAA,MACrC,WAAW,CAACA,OAAc,UAAUC,uBAAsB;AACxD,cAAM,oBAAoBA,mBAAkBD,OAAM;AAAA,UAChD,GAAG;AAAA,UACH,UAAUA;AAAA,UACV,SAAS;AAAA,YACP,IAAI,MAAM,WAAY,CAAC,GAAiB;AAAA,cACtC,CAAC,WAAW,OAAO,OAAO;AAAA,YAC5B;AAAA,UACF;AAAA,QACF,CAAC;AAED,eAAO,CAAC,WAEF;AACJ,gBAAME,YAAW,aAAa,mBAAmB,MAAM;AAEvD,iBAAOD,mBAAkBC,WAAU;AAAA,YACjC,GAAG;AAAA,YACH,SAAS,MAAM;AAAA,YACf,UAAAA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,kBAAkB,UAAU;AAAA,MACjC,GAAG;AAAA,MACH;AAAA,MACA,SAAS;AAAA,MACT,SAAS,CAAC,uBAAuB,GAAI,MAAM,WAAW,CAAC,CAAE;AAAA,IAC3D,CAAC;AAAA,EACH;AACF;AAmBO,MAAM,eAAwB;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,MAAM,aAAa,SAAS;AAAA,EAC1D,WAAW,CAAC,MAAqB,UAC/B,WAAW,KAAK,OAAO,eAAe,KAAK,OAAO,MAAM,KAAK;AACjE;","names":["node","deepTransformNode","children"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getInsertion.ts"],"sourcesContent":["import type { InsertionContent } from '../transpiler';\n\n/**\n * Allow to insert values in a string.\n *\n * Usage:\n *\n * ```ts\n * const content = getInsertion('Hello {{name}}!', {\n * name: 'John',\n * });\n * // 'Hello John!'\n * ```\n *\n */\nexport const getInsertion = (\n content: string,\n values: { [K in InsertionContent['fields'][number]]: string }\n) => content.replace(/\\{\\{(.*?)\\}\\}/g, (_, key) => values[key] ?? '');\n"],"mappings":"AAeO,MAAM,eAAe,CAC1B,SACA,WACG,QAAQ,QAAQ,kBAAkB,CAAC,GAAG,QAAQ,OAAO,GAAG,KAAK,EAAE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\nimport { LanguageContent } from '../types';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: LocalesValues\n): Content => {\n const { defaultLocale } = configuration?.internationalization;\n\n const result =\n languageContent[\n (locale ?? defaultLocale) as unknown as keyof typeof languageContent\n ] ??\n (languageContent[\n defaultLocale as unknown as keyof typeof languageContent\n ] as Content);\n\n return result;\n};\n"],"mappings":"AACA,OAAO,mBAAmB;AAwBnB,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,eAAe;AAEzC,QAAM,SACJ,gBACG,UAAU,aACb,KACC,gBACC,aACF;AAEF,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "fs";
|
|
2
|
+
import {
|
|
3
|
+
formatNodeType,
|
|
4
|
+
NodeType
|
|
5
|
+
} from "../../types/index.mjs";
|
|
6
|
+
import { relative, resolve } from "path";
|
|
7
|
+
import { appLogger } from "@intlayer/config";
|
|
8
|
+
const file = (path) => {
|
|
9
|
+
const callerDir = intlayer_file_dir ?? process.cwd();
|
|
10
|
+
const isAbsolutePath = path.startsWith("/");
|
|
11
|
+
const isRelativePath = path.startsWith("./") || path.startsWith("../");
|
|
12
|
+
let filePath;
|
|
13
|
+
if (isAbsolutePath) {
|
|
14
|
+
appLogger(
|
|
15
|
+
`Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,
|
|
16
|
+
{ level: "warn" }
|
|
17
|
+
);
|
|
18
|
+
filePath = path;
|
|
19
|
+
} else if (isRelativePath) {
|
|
20
|
+
filePath = resolve(callerDir, path);
|
|
21
|
+
} else {
|
|
22
|
+
filePath = resolve(process.cwd(), path);
|
|
23
|
+
}
|
|
24
|
+
let content;
|
|
25
|
+
if (existsSync(filePath)) {
|
|
26
|
+
content = readFileSync(filePath, "utf8");
|
|
27
|
+
} else {
|
|
28
|
+
appLogger(`File not found: ${filePath}`, { level: "warn" });
|
|
29
|
+
content = `File not found`;
|
|
30
|
+
}
|
|
31
|
+
return formatNodeType(NodeType.File, path, {
|
|
32
|
+
content,
|
|
33
|
+
fixedPath: relative(process.cwd(), filePath)
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var file_default = file;
|
|
37
|
+
export {
|
|
38
|
+
file_default as default
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'fs';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { relative, resolve } from 'path';\nimport { appLogger } from '@intlayer/config';\n\nexport type FileContent = TypedNodeModel<\n NodeType.File,\n string,\n {\n content: string;\n fixedPath?: string;\n }\n>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nconst file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(`File not found: ${filePath}`, { level: 'warn' });\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n\nexport default file;\n"],"mappings":"AAAA,SAAS,YAAY,oBAAoB;AACzC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,eAAe;AAClC,SAAS,iBAAiB;AA6B1B,MAAM,OAAO,CAAC,SAA8B;AAC1C,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AAErE,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,eAAW,QAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,eAAW,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,MAAI,WAAW,QAAQ,GAAG;AACxB,cAAU,aAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL,cAAU,mBAAmB,QAAQ,IAAI,EAAE,OAAO,OAAO,CAAC;AAE1D,cAAU;AAAA,EACZ;AAEA,SAAO,eAAe,SAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,WAAW,SAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;AAEA,IAAO,eAAQ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/file/index.ts"],"sourcesContent":["export * from './file';\n"],"mappings":"AAAA,cAAc;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./translation/index.mjs";
|
|
2
2
|
export * from "./enumeration/index.mjs";
|
|
3
3
|
export * from "./condition/index.mjs";
|
|
4
|
+
export * from "./insertion/index.mjs";
|
|
4
5
|
export * from "./markdown/index.mjs";
|
|
5
6
|
export * from "./nesting/index.mjs";
|
|
6
7
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './translation/index';\nexport * from './enumeration/index';\nexport * from './condition/index';\nexport * from './markdown/index';\nexport * from './nesting/index';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/transpiler/index.ts"],"sourcesContent":["export * from './translation/index';\nexport * from './enumeration/index';\nexport * from './condition/index';\nexport * from './insertion/index';\nexport * from './markdown/index';\nexport * from './nesting/index';\n// export * from './file/index';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const getInsertionValues = (content) => {
|
|
2
|
+
const regex = /{{\s*(\w+)\s*}}/g;
|
|
3
|
+
const matches = [...content.matchAll(regex)];
|
|
4
|
+
if (matches.length === 0) return [];
|
|
5
|
+
return matches.map((match) => match[1]);
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
getInsertionValues
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=getInsertionValues.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/insertion/getInsertionValues.ts"],"sourcesContent":["export const getInsertionValues = (content: string): string[] => {\n // Regular expression to match {{field}} patterns\n const regex = /{{\\s*(\\w+)\\s*}}/g;\n const matches = [...content.matchAll(regex)];\n\n // If no matches are found, return undefined\n if (matches.length === 0) return [];\n\n // Extract field names from matches and return as an object with the field names\n return matches.map((match) => match[1]);\n};\n"],"mappings":"AAAO,MAAM,qBAAqB,CAAC,YAA8B;AAE/D,QAAM,QAAQ;AACd,QAAM,UAAU,CAAC,GAAG,QAAQ,SAAS,KAAK,CAAC;AAG3C,MAAI,QAAQ,WAAW,EAAG,QAAO,CAAC;AAGlC,SAAO,QAAQ,IAAI,CAAC,UAAU,MAAM,CAAC,CAAC;AACxC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/insertion/index.ts"],"sourcesContent":["export * from './insertion';\nexport * from './getInsertionValues';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
formatNodeType,
|
|
3
|
+
NodeType
|
|
4
|
+
} from "../../types/index.mjs";
|
|
5
|
+
import { getInsertionValues } from "./getInsertionValues.mjs";
|
|
6
|
+
const insertion = (content) => {
|
|
7
|
+
const getInsertions = () => {
|
|
8
|
+
if (typeof content === "string") {
|
|
9
|
+
return getInsertionValues(content);
|
|
10
|
+
}
|
|
11
|
+
let stringContent = void 0;
|
|
12
|
+
if (typeof content === "function") {
|
|
13
|
+
stringContent = content();
|
|
14
|
+
} else if (typeof content.then === "function") {
|
|
15
|
+
stringContent = async () => getInsertionValues(await content);
|
|
16
|
+
}
|
|
17
|
+
if (typeof stringContent === "string") {
|
|
18
|
+
return getInsertionValues(stringContent);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return getInsertionValues(JSON.stringify(content));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return formatNodeType(NodeType.Insertion, content, {
|
|
27
|
+
fields: getInsertions()
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
insertion as insert
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=insertion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContent<Content = unknown> = TypedNodeModel<\n NodeType.Insertion,\n Content,\n { fields: string[] }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n content: Content\n): InsertionContent<Content> => {\n const getInsertions = () => {\n if (typeof content === 'string') {\n return getInsertionValues(content);\n }\n\n let stringContent = undefined;\n\n if (typeof content === 'function') {\n stringContent = content();\n } else if (typeof (content as Promise<string>).then === 'function') {\n stringContent = async () =>\n getInsertionValues(await (content as Promise<string>));\n }\n\n if (typeof stringContent === 'string') {\n return getInsertionValues(stringContent);\n }\n\n try {\n return getInsertionValues(JSON.stringify(content));\n } catch (e) {\n return [];\n }\n };\n\n return formatNodeType(NodeType.Insertion, content, {\n fields: getInsertions(),\n });\n};\n\nexport { insertion as insert };\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,0BAA0B;AAoBnC,MAAM,YAAY,CAChB,YAC8B;AAC9B,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,YAAY,UAAU;AAC/B,aAAO,mBAAmB,OAAO;AAAA,IACnC;AAEA,QAAI,gBAAgB;AAEpB,QAAI,OAAO,YAAY,YAAY;AACjC,sBAAgB,QAAQ;AAAA,IAC1B,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,sBAAgB,YACd,mBAAmB,MAAO,OAA2B;AAAA,IACzD;AAEA,QAAI,OAAO,kBAAkB,UAAU;AACrC,aAAO,mBAAmB,aAAa;AAAA,IACzC;AAEA,QAAI;AACF,aAAO,mBAAmB,KAAK,UAAU,OAAO,CAAC;AAAA,IACnD,SAAS,GAAG;AACV,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,SAAO,eAAe,SAAS,WAAW,SAAS;AAAA,IACjD,QAAQ,cAAc;AAAA,EACxB,CAAC;AACH;","names":[]}
|