@intlayer/core 7.5.0-canary.0 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +10 -10
- package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +11 -11
- package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +4 -4
- package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +7 -7
- package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +3 -3
- package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +6 -6
- package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +6 -6
- package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +5 -5
- package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +27 -27
- package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +5 -5
- package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +3 -3
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs +11 -11
- package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +5 -5
- package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +3 -3
- package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +4 -4
- package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +4 -4
- package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +3 -3
- package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
- package/dist/cjs/formatters/compact.cjs +3 -3
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +3 -3
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +3 -3
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/list.cjs +3 -3
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +3 -3
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +3 -3
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +3 -3
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +3 -3
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/getStorageAttributes.cjs +4 -4
- package/dist/cjs/getStorageAttributes.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/deepTransform.cjs +3 -3
- package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/getContent.cjs +3 -3
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +18 -18
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs +7 -7
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs +7 -7
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getHTMLTextDir.cjs +39 -26
- package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +8 -8
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocaleFromPath.cjs +5 -5
- package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +6 -6
- package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
- package/dist/cjs/localization/getMultilingualUrls.cjs +6 -6
- package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
- package/dist/cjs/localization/getPathWithoutLocale.cjs +3 -3
- package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
- package/dist/cjs/localization/getPrefix.cjs +6 -6
- package/dist/cjs/localization/getPrefix.cjs.map +1 -1
- package/dist/cjs/localization/localeMapper.cjs +6 -6
- package/dist/cjs/localization/localeMapper.cjs.map +1 -1
- package/dist/cjs/localization/localeResolver.cjs +3 -3
- package/dist/cjs/localization/localeResolver.cjs.map +1 -1
- package/dist/cjs/localization/validatePrefix.cjs +6 -6
- package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
- package/dist/cjs/messageFormat/ICU.cjs +5 -5
- package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
- package/dist/cjs/messageFormat/i18next.cjs +5 -5
- package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
- package/dist/cjs/messageFormat/verify-icu-format.cjs +65 -0
- package/dist/cjs/messageFormat/verify-icu-format.cjs.map +1 -0
- package/dist/cjs/messageFormat/vue-i18n.cjs +5 -5
- package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
- package/dist/cjs/transpiler/condition/condition.cjs +2 -2
- package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs +2 -2
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs +7 -7
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/transpiler/file/fileBrowser.cjs +1 -1
- package/dist/cjs/transpiler/gender/gender.cjs +2 -2
- package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
- package/dist/cjs/transpiler/insertion/insertion.cjs +2 -2
- package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
- package/dist/cjs/transpiler/markdown/markdown.cjs +2 -2
- package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
- package/dist/cjs/transpiler/nesting/nesting.cjs +2 -2
- package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
- package/dist/cjs/transpiler/translation/translation.cjs +2 -2
- package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +3 -3
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +5 -5
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/esm/localization/getHTMLTextDir.mjs +18 -5
- package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
- package/dist/esm/messageFormat/ICU.mjs.map +1 -1
- package/dist/esm/messageFormat/verify-icu-format.mjs +65 -0
- package/dist/esm/messageFormat/verify-icu-format.mjs.map +1 -0
- package/dist/esm/utils/intl.mjs +19 -22
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +8 -8
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/messageFormat/ICU.d.ts.map +1 -1
- package/dist/types/messageFormat/verify-icu-format.d.ts +1 -0
- package/package.json +9 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
|
|
4
4
|
//#region src/transpiler/condition/condition.ts
|
|
5
5
|
/**
|
|
@@ -19,7 +19,7 @@ let __intlayer_types = require("@intlayer/types");
|
|
|
19
19
|
* The last key provided will be used as the fallback value.
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
const condition = (content) => (0,
|
|
22
|
+
const condition = (content) => (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Condition, content);
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
25
|
exports.cond = condition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/condition/condition.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\nexport type ConditionContentStates<Content> = Record<`${boolean}`, Content> & {\n fallback?: Content;\n};\n\nexport type ConditionContent<Content = unknown> = TypedNodeModel<\n NodeType.Condition,\n ConditionContentStates<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a condition.\n *\n * Usage:\n *\n * ```ts\n * cond({\n * 'true': 'The condition is validated',\n * 'false': 'The condition is not validated',\n * });\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n */\nconst condition = <Content>(content?: ConditionContentStates<Content>) =>\n formatNodeType(NodeType.Condition, content);\n\nexport { condition as cond };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,aAAsB,
|
|
1
|
+
{"version":3,"file":"condition.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/condition/condition.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\nexport type ConditionContentStates<Content> = Record<`${boolean}`, Content> & {\n fallback?: Content;\n};\n\nexport type ConditionContent<Content = unknown> = TypedNodeModel<\n NodeType.Condition,\n ConditionContentStates<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a condition.\n *\n * Usage:\n *\n * ```ts\n * cond({\n * 'true': 'The condition is validated',\n * 'false': 'The condition is not validated',\n * });\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n */\nconst condition = <Content>(content?: ConditionContentStates<Content>) =>\n formatNodeType(NodeType.Condition, content);\n\nexport { condition as cond };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA4BA,MAAM,aAAsB,gDACXA,yBAAS,WAAW,QAAQ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
|
|
4
4
|
//#region src/transpiler/enumeration/enumeration.ts
|
|
5
5
|
/**
|
|
@@ -21,7 +21,7 @@ let __intlayer_types = require("@intlayer/types");
|
|
|
21
21
|
* > The order of the keys will define the priority of the content.
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
|
-
const enumeration = (content) => (0,
|
|
24
|
+
const enumeration = (content) => (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Enumeration, content);
|
|
25
25
|
|
|
26
26
|
//#endregion
|
|
27
27
|
exports.enu = enumeration;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enumeration.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\ntype Positive = number | `${number}`;\ntype Negative = `-${number}`;\ntype Numbers = Positive | Negative;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\nexport type EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<Content>\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 * enu({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * });\n * ```\n *\n * > The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,eAAwB,
|
|
1
|
+
{"version":3,"file":"enumeration.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\ntype Positive = number | `${number}`;\ntype Negative = `-${number}`;\ntype Numbers = Positive | Negative;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\nexport type EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<Content>\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 * enu({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * });\n * ```\n *\n * > The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmDA,MAAM,eAAwB,gDACbA,yBAAS,aAAa,QAAQ"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
|
-
let
|
|
5
|
+
let _intlayer_config = require("@intlayer/config");
|
|
6
6
|
|
|
7
7
|
//#region src/transpiler/file/file.ts
|
|
8
8
|
const fileContent = (path, callerDir, baseDir) => {
|
|
9
9
|
const isRelativePath = path.startsWith("./") || path.startsWith("../");
|
|
10
|
-
const appLogger = (0,
|
|
10
|
+
const appLogger = (0, _intlayer_config.getAppLogger)();
|
|
11
11
|
let filePath;
|
|
12
12
|
if ((0, node_path.isAbsolute)(path)) {
|
|
13
13
|
appLogger(`Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${callerDir}`, { level: "warn" });
|
|
@@ -16,15 +16,15 @@ const fileContent = (path, callerDir, baseDir) => {
|
|
|
16
16
|
else filePath = (0, node_path.resolve)(baseDir, path);
|
|
17
17
|
if ((0, node_fs.existsSync)(filePath) && (0, node_fs.statSync)(filePath).isFile()) try {
|
|
18
18
|
const content = (0, node_fs.readFileSync)(filePath, "utf8");
|
|
19
|
-
return (0,
|
|
19
|
+
return (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.File, path, {
|
|
20
20
|
content,
|
|
21
21
|
fixedPath: (0, node_path.relative)(baseDir, filePath)
|
|
22
22
|
});
|
|
23
23
|
} catch {
|
|
24
|
-
appLogger(`Unable to read path: ${(0,
|
|
24
|
+
appLogger(`Unable to read path: ${(0, _intlayer_config.colorizePath)((0, node_path.relative)(baseDir, filePath))}`, { level: "warn" });
|
|
25
25
|
}
|
|
26
|
-
else appLogger(`File not found: ${(0,
|
|
27
|
-
return (0,
|
|
26
|
+
else appLogger(`File not found: ${(0, _intlayer_config.colorizePath)((0, node_path.relative)(baseDir, filePath))}`, { level: "warn" });
|
|
27
|
+
return (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.File, path, { content: `-` });
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Function intended to be used to build intlayer dictionaries.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.cjs","names":["filePath: string","NodeType"],"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, isAbsolute, relative, resolve } from 'node:path';\nimport { colorizePath, getAppLogger } from '@intlayer/config';\nimport { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\nexport const fileContent = (\n path: string,\n callerDir: string,\n baseDir: string\n): FileContent => {\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger();\n\n let filePath: string;\n if (isAbsolute(path)) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${callerDir}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(baseDir, path);\n }\n\n if (existsSync(filePath) && statSync(filePath).isFile()) {\n try {\n const content = readFileSync(filePath, 'utf8');\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(baseDir, filePath),\n });\n } catch {\n appLogger(\n `Unable to read path: ${colorizePath(relative(baseDir, filePath))}`,\n { level: 'warn' }\n );\n }\n } else {\n appLogger(`File not found: ${colorizePath(relative(baseDir, filePath))}`, {\n level: 'warn',\n });\n }\n\n return formatNodeType(NodeType.File, path, {\n content: `-`,\n });\n};\n\ntype GlobalIntlayerFilePath = {\n INTLAYER_FILE_PATH: string;\n INTLAYER_BASE_DIR: string;\n};\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 */\nexport const file = (path: string): FileContent => {\n const { INTLAYER_FILE_PATH, INTLAYER_BASE_DIR } =\n globalThis as unknown as GlobalIntlayerFilePath;\n\n const callerDir = dirname(INTLAYER_FILE_PATH);\n const baseDir = INTLAYER_BASE_DIR;\n\n return fileContent(path, callerDir, baseDir);\n};\n"],"mappings":";;;;;;;AAaA,MAAa,eACX,MACA,WACA,YACgB;CAChB,MAAM,iBAAiB,KAAK,WAAW,KAAK,IAAI,KAAK,WAAW,MAAM;CACtE,MAAM,
|
|
1
|
+
{"version":3,"file":"file.cjs","names":["filePath: string","NodeType"],"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { existsSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, isAbsolute, relative, resolve } from 'node:path';\nimport { colorizePath, getAppLogger } from '@intlayer/config';\nimport { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\nexport const fileContent = (\n path: string,\n callerDir: string,\n baseDir: string\n): FileContent => {\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger();\n\n let filePath: string;\n if (isAbsolute(path)) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${callerDir}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(baseDir, path);\n }\n\n if (existsSync(filePath) && statSync(filePath).isFile()) {\n try {\n const content = readFileSync(filePath, 'utf8');\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(baseDir, filePath),\n });\n } catch {\n appLogger(\n `Unable to read path: ${colorizePath(relative(baseDir, filePath))}`,\n { level: 'warn' }\n );\n }\n } else {\n appLogger(`File not found: ${colorizePath(relative(baseDir, filePath))}`, {\n level: 'warn',\n });\n }\n\n return formatNodeType(NodeType.File, path, {\n content: `-`,\n });\n};\n\ntype GlobalIntlayerFilePath = {\n INTLAYER_FILE_PATH: string;\n INTLAYER_BASE_DIR: string;\n};\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 */\nexport const file = (path: string): FileContent => {\n const { INTLAYER_FILE_PATH, INTLAYER_BASE_DIR } =\n globalThis as unknown as GlobalIntlayerFilePath;\n\n const callerDir = dirname(INTLAYER_FILE_PATH);\n const baseDir = INTLAYER_BASE_DIR;\n\n return fileContent(path, callerDir, baseDir);\n};\n"],"mappings":";;;;;;;AAaA,MAAa,eACX,MACA,WACA,YACgB;CAChB,MAAM,iBAAiB,KAAK,WAAW,KAAK,IAAI,KAAK,WAAW,MAAM;CACtE,MAAM,gDAA0B;CAEhC,IAAIA;AACJ,+BAAe,KAAK,EAAE;AACpB,YACE,sFAAsF,KAAK,mBAAmB,aAC9G,EAAE,OAAO,QAAQ,CAClB;AACD,aAAW;YACF,eACT,mCAAmB,WAAW,KAAK;KAEnC,mCAAmB,SAAS,KAAK;AAGnC,6BAAe,SAAS,0BAAa,SAAS,CAAC,QAAQ,CACrD,KAAI;EACF,MAAM,oCAAuB,UAAU,OAAO;AAE9C,6CAAsBC,yBAAS,MAAM,MAAM;GACzC;GACA,mCAAoB,SAAS,SAAS;GACvC,CAAC;SACI;AACN,YACE,mFAA8C,SAAS,SAAS,CAAC,IACjE,EAAE,OAAO,QAAQ,CAClB;;KAGH,WAAU,8EAAyC,SAAS,SAAS,CAAC,IAAI,EACxE,OAAO,QACR,CAAC;AAGJ,4CAAsBA,yBAAS,MAAM,MAAM,EACzC,SAAS,KACV,CAAC;;;;;;;;;;;;;;;;;AAuBJ,MAAa,QAAQ,SAA8B;CACjD,MAAM,EAAE,oBAAoB,sBAC1B;AAKF,QAAO,YAAY,6BAHO,mBAAmB,EAC7B,kBAE4B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
|
|
4
4
|
//#region src/transpiler/gender/gender.ts
|
|
5
5
|
/**
|
|
@@ -19,7 +19,7 @@ let __intlayer_types = require("@intlayer/types");
|
|
|
19
19
|
* The last key provided will be used as the fallback value.
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
const gender = (content) => (0,
|
|
22
|
+
const gender = (content) => (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Gender, content);
|
|
23
23
|
|
|
24
24
|
//#endregion
|
|
25
25
|
exports.gender = gender;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gender.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/gender/gender.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\nexport type Gender = 'male' | 'female' | 'fallback';\n\nexport type GenderContentStates<Content> = Record<`${Gender}`, Content> & {\n fallback?: Content;\n};\n\nexport type GenderContent<Content = unknown> = TypedNodeModel<\n NodeType.Gender,\n GenderContentStates<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a gender.\n *\n * Usage:\n *\n * ```ts\n * gender({\n * 'true': 'The gender is validated',\n * 'false': 'The gender is not validated',\n * });\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n */\nconst gender = <Content>(content?: GenderContentStates<Content>) =>\n formatNodeType(NodeType.Gender, content);\n\nexport { gender };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,UAAmB,
|
|
1
|
+
{"version":3,"file":"gender.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/gender/gender.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\n\nexport type Gender = 'male' | 'female' | 'fallback';\n\nexport type GenderContentStates<Content> = Record<`${Gender}`, Content> & {\n fallback?: Content;\n};\n\nexport type GenderContent<Content = unknown> = TypedNodeModel<\n NodeType.Gender,\n GenderContentStates<Content>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to pick a content based on a gender.\n *\n * Usage:\n *\n * ```ts\n * gender({\n * 'true': 'The gender is validated',\n * 'false': 'The gender is not validated',\n * });\n * ```\n *\n * The last key provided will be used as the fallback value.\n *\n */\nconst gender = <Content>(content?: GenderContentStates<Content>) =>\n formatNodeType(NodeType.Gender, content);\n\nexport { gender };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,UAAmB,gDACRA,yBAAS,QAAQ,QAAQ"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_transpiler_insertion_getInsertionValues = require('./getInsertionValues.cjs');
|
|
3
|
-
let
|
|
3
|
+
let _intlayer_types = require("@intlayer/types");
|
|
4
4
|
|
|
5
5
|
//#region src/transpiler/insertion/insertion.ts
|
|
6
6
|
/**
|
|
@@ -28,7 +28,7 @@ const insertion = (content) => {
|
|
|
28
28
|
return [];
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
return (0,
|
|
31
|
+
return (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Insertion, content, { fields: getInsertions() });
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertion.cjs","names":["getInsertionValues","NodeType"],"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructor<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructor<\n Content,\n {\n fields: string[];\n }\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;\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":";;;;;;;;;;;;;;;;;AA2BA,MAAM,aACJ,YAC8B;CAC9B,MAAM,sBAAsB;AAC1B,MAAI,OAAO,YAAY,SACrB,QAAOA,mEAAmB,QAAQ;EAGpC,IAAI;AAEJ,MAAI,OAAO,YAAY,WACrB,iBAAgB,SAAS;WAChB,OAAQ,QAA4B,SAAS,WACtD,iBAAgB,YACdA,mEAAmB,MAAO,QAA4B;AAG1D,MAAI,OAAO,kBAAkB,SAC3B,QAAOA,mEAAmB,cAAc;AAG1C,MAAI;AACF,UAAOA,mEAAmB,KAAK,UAAU,QAAQ,CAAC;WAC3C,IAAI;AACX,UAAO,EAAE;;;AAIb,
|
|
1
|
+
{"version":3,"file":"insertion.cjs","names":["getInsertionValues","NodeType"],"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructor<\n Content = unknown,\n T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructor<\n Content,\n {\n fields: string[];\n }\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;\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":";;;;;;;;;;;;;;;;;AA2BA,MAAM,aACJ,YAC8B;CAC9B,MAAM,sBAAsB;AAC1B,MAAI,OAAO,YAAY,SACrB,QAAOA,mEAAmB,QAAQ;EAGpC,IAAI;AAEJ,MAAI,OAAO,YAAY,WACrB,iBAAgB,SAAS;WAChB,OAAQ,QAA4B,SAAS,WACtD,iBAAgB,YACdA,mEAAmB,MAAO,QAA4B;AAG1D,MAAI,OAAO,kBAAkB,SAC3B,QAAOA,mEAAmB,cAAc;AAG1C,MAAI;AACF,UAAOA,mEAAmB,KAAK,UAAU,QAAQ,CAAC;WAC3C,IAAI;AACX,UAAO,EAAE;;;AAIb,4CAAsBC,yBAAS,WAAW,SAAS,EACjD,QAAQ,eAAe,EACxB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_interpreter_getContent_getContent = require('../../interpreter/getContent/getContent.cjs');
|
|
3
3
|
const require_transpiler_markdown_getMarkdownMetadata = require('./getMarkdownMetadata.cjs');
|
|
4
|
-
let
|
|
4
|
+
let _intlayer_types = require("@intlayer/types");
|
|
5
5
|
|
|
6
6
|
//#region src/transpiler/markdown/markdown.ts
|
|
7
7
|
const awaitContent = async (content) => {
|
|
@@ -29,7 +29,7 @@ const markdown = (content) => {
|
|
|
29
29
|
});
|
|
30
30
|
if (typeof flatContent === "string") return require_transpiler_markdown_getMarkdownMetadata.getMarkdownMetadata(flatContent);
|
|
31
31
|
};
|
|
32
|
-
return (0,
|
|
32
|
+
return (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Markdown, content, { metadata });
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.cjs","names":["getContent","getMarkdownMetadata","NodeType"],"sources":["../../../../src/transpiler/markdown/markdown.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getContent } from '../../interpreter/getContent/getContent';\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 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,MAAM,eAAe,OAAO,YAAiB;AAC3C,KAAI,OAAO,YAAY,YAAY,OAAO,YAAY,SACpD,QAAO;AAGT,KAAI,OAAO,YAAY,WACrB,QAAO,SAAS;AAElB,KAAI,OAAO,QAAQ,SAAS,WAC1B,QAAO,MAAM;;;;;;;;;;;;;;AAgBjB,MAAM,YAA+B,YAAsC;CACzE,MAAM,WAAW,YAAY;EAG3B,MAAM,cAAcA,qDAFG,MAAM,aAAa,QAAQ,EAEH;GAC7C,eAAe;GACf,SAAS,EAAE;GACZ,CAAC;AAEF,MAAI,OAAO,gBAAgB,SACzB,QAAOC,oEAAoB,YAAY;;AAI3C,
|
|
1
|
+
{"version":3,"file":"markdown.cjs","names":["getContent","getMarkdownMetadata","NodeType"],"sources":["../../../../src/transpiler/markdown/markdown.ts"],"sourcesContent":["import { formatNodeType, NodeType, type TypedNodeModel } from '@intlayer/types';\nimport { getContent } from '../../interpreter/getContent/getContent';\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 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,MAAM,eAAe,OAAO,YAAiB;AAC3C,KAAI,OAAO,YAAY,YAAY,OAAO,YAAY,SACpD,QAAO;AAGT,KAAI,OAAO,YAAY,WACrB,QAAO,SAAS;AAElB,KAAI,OAAO,QAAQ,SAAS,WAC1B,QAAO,MAAM;;;;;;;;;;;;;;AAgBjB,MAAM,YAA+B,YAAsC;CACzE,MAAM,WAAW,YAAY;EAG3B,MAAM,cAAcA,qDAFG,MAAM,aAAa,QAAQ,EAEH;GAC7C,eAAe;GACf,SAAS,EAAE;GACZ,CAAC;AAEF,MAAI,OAAO,gBAAgB,SACzB,QAAOC,oEAAoB,YAAY;;AAI3C,4CAAsBC,yBAAS,UAAU,SAAmB,EAC1D,UACD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
|
|
4
4
|
//#region src/transpiler/nesting/nesting.ts
|
|
5
5
|
/**
|
|
@@ -17,7 +17,7 @@ let __intlayer_types = require("@intlayer/types");
|
|
|
17
17
|
* The order of the keys will define the priority of the content.
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
const nesting = (dictionaryKey, path) => (0,
|
|
20
|
+
const nesting = (dictionaryKey, path) => (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Nested, {
|
|
21
21
|
dictionaryKey,
|
|
22
22
|
path
|
|
23
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nesting.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/nesting/nesting.ts"],"sourcesContent":["import type { DictionaryRegistryContent } from '@intlayer/types';\nimport {\n type DictionaryKeys,\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '@intlayer/types';\nimport type { DeepTransformContent } from '../../interpreter';\n\n/**\n * Recursively builds dot-notation strings for all valid paths in T.\n * Example:\n * type X = { a: { b: { c: string }}, d: number };\n * DotPath<X> = \"a\" | \"a.b\" | \"a.b.c\" | \"d\"\n */\nexport type DotPath<T> = T extends object\n ? {\n [K in keyof T & (string | number)]: T[K] extends object\n ? // Either just K, or K + '.' + deeper path\n `${K}` | `${K}.${DotPath<T[K]>}`\n : `${K}`;\n }[keyof T & (string | number)]\n : never;\n\ntype DeepReplace<T, From, To> = T extends From\n ? To\n : T extends object\n ? { [K in keyof T]: DeepReplace<T[K], From, To> }\n : T;\n\n/** Build all valid dot-notation strings for a dictionary entry. */\nexport type ValidDotPathsFor<K extends DictionaryKeys> = DotPath<\n DeepReplace<\n DeepTransformContent<DictionaryRegistryContent<K>>,\n // Replace ReactElement type with string\n {\n type: any;\n props: any;\n key: any;\n },\n string\n >\n>;\n\nexport type NestedContentState<K extends DictionaryKeys> = {\n dictionaryKey: K;\n\n /**\n * Path must match existing keys in DictionaryRegistryContent<K>.\n * Can be either:\n * - \"dot.dot.dot\" format\n */\n path?: ValidDotPathsFor<K>;\n};\n\nexport type NestedContent<K extends DictionaryKeys = never> = TypedNodeModel<\n NodeType.Nested,\n NestedContentState<K>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to extract the content of another dictionary and nest it in the current dictionary.\n *\n * Usage:\n *\n * ```ts\n * nest(\"dictionaryKey\");\n * nest(\"dictionaryKey\", \"path.to.content\");\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n */\nconst nesting = <K extends DictionaryKeys>(\n dictionaryKey: K,\n path?: ValidDotPathsFor<K>\n): NestedContent<K> =>\n formatNodeType(NodeType.Nested, {\n dictionaryKey,\n path,\n });\n\nexport { nesting as nest };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2EA,MAAM,WACJ,eACA,
|
|
1
|
+
{"version":3,"file":"nesting.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/nesting/nesting.ts"],"sourcesContent":["import type { DictionaryRegistryContent } from '@intlayer/types';\nimport {\n type DictionaryKeys,\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '@intlayer/types';\nimport type { DeepTransformContent } from '../../interpreter';\n\n/**\n * Recursively builds dot-notation strings for all valid paths in T.\n * Example:\n * type X = { a: { b: { c: string }}, d: number };\n * DotPath<X> = \"a\" | \"a.b\" | \"a.b.c\" | \"d\"\n */\nexport type DotPath<T> = T extends object\n ? {\n [K in keyof T & (string | number)]: T[K] extends object\n ? // Either just K, or K + '.' + deeper path\n `${K}` | `${K}.${DotPath<T[K]>}`\n : `${K}`;\n }[keyof T & (string | number)]\n : never;\n\ntype DeepReplace<T, From, To> = T extends From\n ? To\n : T extends object\n ? { [K in keyof T]: DeepReplace<T[K], From, To> }\n : T;\n\n/** Build all valid dot-notation strings for a dictionary entry. */\nexport type ValidDotPathsFor<K extends DictionaryKeys> = DotPath<\n DeepReplace<\n DeepTransformContent<DictionaryRegistryContent<K>>,\n // Replace ReactElement type with string\n {\n type: any;\n props: any;\n key: any;\n },\n string\n >\n>;\n\nexport type NestedContentState<K extends DictionaryKeys> = {\n dictionaryKey: K;\n\n /**\n * Path must match existing keys in DictionaryRegistryContent<K>.\n * Can be either:\n * - \"dot.dot.dot\" format\n */\n path?: ValidDotPathsFor<K>;\n};\n\nexport type NestedContent<K extends DictionaryKeys = never> = TypedNodeModel<\n NodeType.Nested,\n NestedContentState<K>\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to extract the content of another dictionary and nest it in the current dictionary.\n *\n * Usage:\n *\n * ```ts\n * nest(\"dictionaryKey\");\n * nest(\"dictionaryKey\", \"path.to.content\");\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n */\nconst nesting = <K extends DictionaryKeys>(\n dictionaryKey: K,\n path?: ValidDotPathsFor<K>\n): NestedContent<K> =>\n formatNodeType(NodeType.Nested, {\n dictionaryKey,\n path,\n });\n\nexport { nesting as nest };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA2EA,MAAM,WACJ,eACA,6CAEeA,yBAAS,QAAQ;CAC9B;CACA;CACD,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
|
|
4
4
|
//#region src/transpiler/translation/translation.ts
|
|
5
5
|
/**
|
|
@@ -22,7 +22,7 @@ let __intlayer_types = require("@intlayer/types");
|
|
|
22
22
|
* - this function require each locale to be defined if defined in the project configuration.
|
|
23
23
|
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
24
24
|
*/
|
|
25
|
-
const translation = (content) => (0,
|
|
25
|
+
const translation = (content) => (0, _intlayer_types.formatNodeType)(_intlayer_types.NodeType.Translation, content);
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
28
|
exports.t = translation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/translation/translation.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type StrictModeLocaleMap,\n type TypedNodeModel,\n} from '@intlayer/types';\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends\n StrictModeLocaleMap<Content> = StrictModeLocaleMap<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\n StrictModeLocaleMap<Content> = StrictModeLocaleMap<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":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,eAKJ,
|
|
1
|
+
{"version":3,"file":"translation.cjs","names":["NodeType"],"sources":["../../../../src/transpiler/translation/translation.ts"],"sourcesContent":["import {\n formatNodeType,\n NodeType,\n type StrictModeLocaleMap,\n type TypedNodeModel,\n} from '@intlayer/types';\n\nexport type TranslationContent<\n Content = unknown,\n RecordContent extends\n StrictModeLocaleMap<Content> = StrictModeLocaleMap<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\n StrictModeLocaleMap<Content> = StrictModeLocaleMap<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":";;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,eAKJ,gDAEeA,yBAAS,aAAa,QAAQ"}
|
package/dist/cjs/utils/intl.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_types = require("@intlayer/types");
|
|
3
3
|
|
|
4
4
|
//#region src/utils/intl.ts
|
|
5
5
|
const cacheKey = (locales, options) => JSON.stringify([locales, options]);
|
|
@@ -7,7 +7,7 @@ const createCachedConstructor = (Ctor) => {
|
|
|
7
7
|
const cache = /* @__PURE__ */ new Map();
|
|
8
8
|
function Wrapped(locales, options) {
|
|
9
9
|
if (Ctor.name === "DisplayNames" && typeof Intl?.DisplayNames !== "function") {
|
|
10
|
-
if (process.env.NODE_ENV === "development")
|
|
10
|
+
if (process.env.NODE_ENV === "development") throw new Error([
|
|
11
11
|
`// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,
|
|
12
12
|
`// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,
|
|
13
13
|
``,
|
|
@@ -28,7 +28,7 @@ const createCachedConstructor = (Ctor) => {
|
|
|
28
28
|
].join("\n"));
|
|
29
29
|
return locales;
|
|
30
30
|
}
|
|
31
|
-
const key = cacheKey(locales ??
|
|
31
|
+
const key = cacheKey(locales ?? _intlayer_types.Locales.ENGLISH, options);
|
|
32
32
|
let instance = cache.get(key);
|
|
33
33
|
if (!instance) {
|
|
34
34
|
instance = new Ctor(locales, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intl.cjs","names":["Locales","instance: InstanceType<T> | undefined"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n
|
|
1
|
+
{"version":3,"file":"intl.cjs","names":["Locales","instance: InstanceType<T> | undefined"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (\n locales?: LocalesValues,\n options?: Options\n ) => Instance\n : T extends new (\n locales: any\n ) => infer Instance\n ? new (\n locales?: LocalesValues\n ) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n throw new Error(\n [\n `// Intl.DisplayNames is not supported; falling back to raw locale (${locales}). `,\n `// Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`,\n ``,\n `import 'intl';`,\n `import '@formatjs/intl-getcanonicallocales/polyfill';`,\n `import '@formatjs/intl-locale/polyfill';`,\n `import '@formatjs/intl-pluralrules/polyfill';`,\n `import '@formatjs/intl-displaynames/polyfill';`,\n `import '@formatjs/intl-listformat/polyfill';`,\n `import '@formatjs/intl-numberformat/polyfill';`,\n `import '@formatjs/intl-relativetimeformat/polyfill';`,\n `import '@formatjs/intl-datetimeformat/polyfill';`,\n ``,\n `// Optionally add locale data`,\n `import '@formatjs/intl-pluralrules/locale-data/fr';`,\n `import '@formatjs/intl-numberformat/locale-data/fr';`,\n `import '@formatjs/intl-datetimeformat/locale-data/fr';`,\n ].join('\\n')\n );\n }\n return locales as any;\n }\n\n const key = cacheKey(locales ?? Locales.ENGLISH, options);\n let instance: InstanceType<T> | undefined = cache.get(key);\n\n if (!instance) {\n instance = new Ctor(locales as never, options as never);\n cache.set(key, instance as InstanceType<T>);\n }\n\n return instance as InstanceType<T>;\n }\n\n // Ensure it behaves like a constructor when used with `new`.\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n// Factory that turns the global `Intl` into a cached clone.\nexport const createCachedIntl = (): WrappedIntl =>\n new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap *only* constructor functions (safest heuristic: they start with a capital letter).\n return typeof value === 'function' && /^[A-Z]/.test(String(prop))\n ? createCachedConstructor(value)\n : value;\n },\n }) as unknown as WrappedIntl;\n\n// Singleton – import this in application code if you just want shared caches.\nexport const CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\n\nexport { CachedIntl as Intl };\n"],"mappings":";;;;AA+DA,MAAM,YAAY,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,QAAQ,CAAC;AAKpC,MAAM,2BACJ,SACG;CACH,MAAM,wBAAQ,IAAI,KAA8B;CAEhD,SAAS,QAAQ,SAAyB,SAAe;AAEvD,MACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,OAAI,QAAQ,IAAI,aAAa,cAC3B,OAAM,IAAI,MACR;IACE,sEAAsE,QAAQ;IAC9E;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACD,CAAC,KAAK,KAAK,CACb;AAEH,UAAO;;EAGT,MAAM,MAAM,SAAS,WAAWA,wBAAQ,SAAS,QAAQ;EACzD,IAAIC,WAAwC,MAAM,IAAI,IAAI;AAE1D,MAAI,CAAC,UAAU;AACb,cAAW,IAAI,KAAK,SAAkB,QAAiB;AACvD,SAAM,IAAI,KAAK,SAA4B;;AAG7C,SAAO;;AAIT,CAAC,QAAgB,YAAa,KAAa;AAE3C,QAAO;;AAIT,MAAa,yBACX,IAAI,MAAM,MAA0B,EAClC,MAAM,QAAQ,MAAM,aAAa;CAC/B,MAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,SAAS;AAGjD,QAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,KAAK,CAAC,GAC7D,wBAAwB,MAAM,GAC9B;GAEP,CAAC;AAGJ,MAAa,aAAa,kBAAkB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_getStorageAttributes = require('../getStorageAttributes.cjs');
|
|
3
3
|
const require_utils_getCookie = require('./getCookie.cjs');
|
|
4
|
-
let
|
|
5
|
-
|
|
4
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
5
|
+
_intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built);
|
|
6
6
|
|
|
7
7
|
//#region src/utils/localeStorage.ts
|
|
8
8
|
const buildCookieString = (name, value, attributes) => {
|
|
@@ -21,7 +21,7 @@ const buildCookieString = (name, value, attributes) => {
|
|
|
21
21
|
* @returns The locale if found in any storage, or undefined if not found
|
|
22
22
|
*/
|
|
23
23
|
const getLocaleFromStorage = (options) => {
|
|
24
|
-
const { routing, internationalization } =
|
|
24
|
+
const { routing, internationalization } = _intlayer_config_built.default;
|
|
25
25
|
const { locales } = internationalization;
|
|
26
26
|
const { storage } = routing;
|
|
27
27
|
if (storage === false || options?.isCookieEnabled === false) return void 0;
|
|
@@ -72,8 +72,8 @@ const getLocaleFromStorage = (options) => {
|
|
|
72
72
|
* @param locale - The locale to store
|
|
73
73
|
*/
|
|
74
74
|
const setLocaleInStorage = (locale, options) => {
|
|
75
|
-
if (
|
|
76
|
-
const storageAttributes = require_getStorageAttributes.getStorageAttributes(
|
|
75
|
+
if (_intlayer_config_built.default.routing.storage === false || options?.isCookieEnabled === false) return;
|
|
76
|
+
const storageAttributes = require_getStorageAttributes.getStorageAttributes(_intlayer_config_built.default.routing.storage);
|
|
77
77
|
for (let i = 0; i < storageAttributes.cookies.length; i++) {
|
|
78
78
|
const { name, attributes } = storageAttributes.cookies[i];
|
|
79
79
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeStorage.cjs","names":["parts: string[]","configuration","getStorageAttributes","getCookie"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { CookiesAttributes, Locale, LocalesValues } from '@intlayer/types';\nimport { getStorageAttributes } from '../getStorageAttributes';\nimport { getCookie } from './getCookie';\n\ntype CookieBuildAttributes = {\n /**\n * Cookie domain to store the locale information\n *\n * Default: undefined\n *\n * Define the domain where the cookie is available. Defaults to\n * the domain of the page where the cookie was created.\n */\n domain?: string;\n /**\n * Cookie path to store the locale information\n *\n * Default: undefined\n *\n * Define the path where the cookie is available. Defaults to '/'\n */\n path?: string;\n /**\n * Cookie secure to store the locale information\n *\n * Default: undefined\n *\n * A Boolean indicating if the cookie transmission requires a\n * secure protocol (https). Defaults to false.\n */\n secure?: boolean;\n /**\n * Cookie httpOnly to store the locale information\n *\n * Default: undefined\n *\n * The cookie httpOnly where the locale information is stored.\n */\n httpOnly?: boolean;\n /**\n * Cookie sameSite to store the locale information\n *\n * Default: undefined\n *\n * Asserts that a cookie must not be sent with cross-origin requests,\n * providing some protection against cross-site request forgery\n * attacks (CSRF)\n */\n sameSite?: 'strict' | 'lax' | 'none';\n\n /**\n * Cookie expires to store the locale information\n *\n * Default: undefined\n *\n * Define when the cookie will be removed. Value can be a Number\n * which will be interpreted as days from time of creation or a\n * Date instance. If omitted, the cookie becomes a session cookie.\n */\n expires?: number | undefined;\n};\n\nconst buildCookieString = (\n name: string,\n value: string,\n attributes: Omit<CookiesAttributes, 'name' | 'type'>\n): string => {\n const encodedValue = encodeURIComponent(value);\n const parts: string[] = [`${name}=${encodedValue}`];\n\n if (attributes.path) parts.push(`Path=${attributes.path}`);\n if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n if (attributes.expires instanceof Date)\n parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\n if (attributes.secure) parts.push('Secure');\n if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n return parts.join('; ');\n};\n\nexport type LocaleStorageOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { routing, internationalization } = configuration;\n const { locales } = internationalization;\n const { storage } = routing;\n\n // If storage is disabled, return undefined\n if (storage === false || options?.isCookieEnabled === false) return undefined;\n\n const storageAttributes = getStorageAttributes(storage);\n\n const isValidLocale = (value: string | null | undefined): value is Locale => {\n if (!value) return false;\n\n return locales.includes(value as Locale);\n };\n\n const readCookie = (name: string): string | undefined => {\n // Prefer provided getter (server or custom environment)\n try {\n const fromOption = options?.getCookie?.(name);\n\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n\n // Fallback to browser cookie parsing\n return getCookie(name);\n };\n\n // 1) Check cookies first\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name } = storageAttributes.cookies[i];\n\n const value = readCookie(name);\n\n if (isValidLocale(value)) return value;\n }\n\n // 2) Then check localStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const value = options?.getLocaleStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 3) Check sessionStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const value = options?.getSessionStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 4) Finally check header candidates (server only)\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n const value = options?.getHeader?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n};\n\n/**\n * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @param locale - The locale to store\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n // If storage is disabled, do nothing\n if (\n configuration.routing.storage === false ||\n options?.isCookieEnabled === false\n )\n return;\n\n const storageAttributes = getStorageAttributes(configuration.routing.storage);\n\n // Write to cookies (server via setCookie, client via cookieStore/document)\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name, attributes } = storageAttributes.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options?.setCookieStore?.(name, locale, {\n ...attributes,\n expires:\n attributes.expires instanceof Date\n ? attributes.expires.getTime()\n : attributes.expires,\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n const cookieString = buildCookieString(name, locale, attributes);\n\n options?.setCookieString?.(name, cookieString);\n }\n } catch {}\n }\n }\n\n // Write to localStorage (browser only)\n if (options?.setLocaleStorage) {\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getLocaleStorage) {\n const existing = options?.getLocaleStorage?.(name);\n if (existing) continue;\n }\n options?.setLocaleStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to sessionStorage (browser only)\n if (options?.setSessionStorage) {\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getSessionStorage) {\n const existing = options?.getSessionStorage?.(name);\n if (existing) continue;\n }\n\n options?.setSessionStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to headers (server only)\n if (options?.setHeader) {\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n options?.setHeader?.(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in the storage by considering the configuration\n *\n * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"localeStorage.cjs","names":["parts: string[]","configuration","getStorageAttributes","getCookie"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { CookiesAttributes, Locale, LocalesValues } from '@intlayer/types';\nimport { getStorageAttributes } from '../getStorageAttributes';\nimport { getCookie } from './getCookie';\n\ntype CookieBuildAttributes = {\n /**\n * Cookie domain to store the locale information\n *\n * Default: undefined\n *\n * Define the domain where the cookie is available. Defaults to\n * the domain of the page where the cookie was created.\n */\n domain?: string;\n /**\n * Cookie path to store the locale information\n *\n * Default: undefined\n *\n * Define the path where the cookie is available. Defaults to '/'\n */\n path?: string;\n /**\n * Cookie secure to store the locale information\n *\n * Default: undefined\n *\n * A Boolean indicating if the cookie transmission requires a\n * secure protocol (https). Defaults to false.\n */\n secure?: boolean;\n /**\n * Cookie httpOnly to store the locale information\n *\n * Default: undefined\n *\n * The cookie httpOnly where the locale information is stored.\n */\n httpOnly?: boolean;\n /**\n * Cookie sameSite to store the locale information\n *\n * Default: undefined\n *\n * Asserts that a cookie must not be sent with cross-origin requests,\n * providing some protection against cross-site request forgery\n * attacks (CSRF)\n */\n sameSite?: 'strict' | 'lax' | 'none';\n\n /**\n * Cookie expires to store the locale information\n *\n * Default: undefined\n *\n * Define when the cookie will be removed. Value can be a Number\n * which will be interpreted as days from time of creation or a\n * Date instance. If omitted, the cookie becomes a session cookie.\n */\n expires?: number | undefined;\n};\n\nconst buildCookieString = (\n name: string,\n value: string,\n attributes: Omit<CookiesAttributes, 'name' | 'type'>\n): string => {\n const encodedValue = encodeURIComponent(value);\n const parts: string[] = [`${name}=${encodedValue}`];\n\n if (attributes.path) parts.push(`Path=${attributes.path}`);\n if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n if (attributes.expires instanceof Date)\n parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\n if (attributes.secure) parts.push('Secure');\n if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n return parts.join('; ');\n};\n\nexport type LocaleStorageOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { routing, internationalization } = configuration;\n const { locales } = internationalization;\n const { storage } = routing;\n\n // If storage is disabled, return undefined\n if (storage === false || options?.isCookieEnabled === false) return undefined;\n\n const storageAttributes = getStorageAttributes(storage);\n\n const isValidLocale = (value: string | null | undefined): value is Locale => {\n if (!value) return false;\n\n return locales.includes(value as Locale);\n };\n\n const readCookie = (name: string): string | undefined => {\n // Prefer provided getter (server or custom environment)\n try {\n const fromOption = options?.getCookie?.(name);\n\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n\n // Fallback to browser cookie parsing\n return getCookie(name);\n };\n\n // 1) Check cookies first\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name } = storageAttributes.cookies[i];\n\n const value = readCookie(name);\n\n if (isValidLocale(value)) return value;\n }\n\n // 2) Then check localStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const value = options?.getLocaleStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 3) Check sessionStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const value = options?.getSessionStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 4) Finally check header candidates (server only)\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n const value = options?.getHeader?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n};\n\n/**\n * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @param locale - The locale to store\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n // If storage is disabled, do nothing\n if (\n configuration.routing.storage === false ||\n options?.isCookieEnabled === false\n )\n return;\n\n const storageAttributes = getStorageAttributes(configuration.routing.storage);\n\n // Write to cookies (server via setCookie, client via cookieStore/document)\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name, attributes } = storageAttributes.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options?.setCookieStore?.(name, locale, {\n ...attributes,\n expires:\n attributes.expires instanceof Date\n ? attributes.expires.getTime()\n : attributes.expires,\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n const cookieString = buildCookieString(name, locale, attributes);\n\n options?.setCookieString?.(name, cookieString);\n }\n } catch {}\n }\n }\n\n // Write to localStorage (browser only)\n if (options?.setLocaleStorage) {\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getLocaleStorage) {\n const existing = options?.getLocaleStorage?.(name);\n if (existing) continue;\n }\n options?.setLocaleStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to sessionStorage (browser only)\n if (options?.setSessionStorage) {\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getSessionStorage) {\n const existing = options?.getSessionStorage?.(name);\n if (existing) continue;\n }\n\n options?.setSessionStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to headers (server only)\n if (options?.setHeader) {\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n options?.setHeader?.(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in the storage by considering the configuration\n *\n * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":"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"}
|
|
@@ -17,10 +17,6 @@ import { Locales } from "@intlayer/types";
|
|
|
17
17
|
const getHTMLTextDir = (locale) => {
|
|
18
18
|
switch (locale) {
|
|
19
19
|
case Locales.ARABIC:
|
|
20
|
-
case Locales.FARSI:
|
|
21
|
-
case Locales.URDU:
|
|
22
|
-
case Locales.PASHTO:
|
|
23
|
-
case Locales.SYRIAC:
|
|
24
20
|
case Locales.ARABIC_UNITED_ARAB_EMIRATES:
|
|
25
21
|
case Locales.ARABIC_BAHRAIN:
|
|
26
22
|
case Locales.ARABIC_ALGERIA:
|
|
@@ -37,10 +33,27 @@ const getHTMLTextDir = (locale) => {
|
|
|
37
33
|
case Locales.ARABIC_SYRIA:
|
|
38
34
|
case Locales.ARABIC_TUNISIA:
|
|
39
35
|
case Locales.ARABIC_YEMEN:
|
|
36
|
+
case Locales.ARABIC_MAURITANIA:
|
|
37
|
+
case Locales.ARABIC_PALESTINE:
|
|
38
|
+
case Locales.ARABIC_SUDAN:
|
|
39
|
+
case Locales.ARABIC_DJIBOUTI:
|
|
40
|
+
case Locales.ARABIC_SOMALIA:
|
|
41
|
+
case Locales.ARABIC_CHAD:
|
|
42
|
+
case Locales.ARABIC_COMOROS:
|
|
43
|
+
case Locales.HEBREW:
|
|
44
|
+
case Locales.HEBREW_ISRAEL:
|
|
45
|
+
case Locales.FARSI:
|
|
40
46
|
case Locales.FARSI_IRAN:
|
|
47
|
+
case Locales.URDU:
|
|
41
48
|
case Locales.URDU_ISLAMIC_REPUBLIC_OF_PAKISTAN:
|
|
49
|
+
case Locales.PASHTO:
|
|
42
50
|
case Locales.PASHTO_AFGHANISTAN:
|
|
43
|
-
case Locales.
|
|
51
|
+
case Locales.SYRIAC:
|
|
52
|
+
case Locales.SYRIAC_SYRIA:
|
|
53
|
+
case Locales.DIVEHI:
|
|
54
|
+
case Locales.DIVEHI_MALDIVES:
|
|
55
|
+
case Locales.YIDDISH:
|
|
56
|
+
case Locales.YIDDISH_WORLD: return "rtl";
|
|
44
57
|
default: return "ltr";
|
|
45
58
|
}
|
|
46
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHTMLTextDir.mjs","names":[],"sources":["../../../src/localization/getHTMLTextDir.ts"],"sourcesContent":["import { Locales, type LocalesValues } from '@intlayer/types';\n\ntype Dir = 'ltr' | 'rtl' | 'auto';\n\n/**\n * Returns the text direction of the given locale.\n *\n * Example:\n *\n * getHTMLTextDir('en-US') // 'ltr'\n * getHTMLTextDir('en') // 'ltr'\n * getHTMLTextDir('fr-CA') // 'ltr'\n * getHTMLTextDir('fr') // 'ltr'\n *\n * @param locale The locale to get the text direction for.\n * @returns The text direction of the given locale.\n */\nexport const getHTMLTextDir = (locale?: LocalesValues): Dir => {\n switch (locale) {\n case Locales.ARABIC:\n case Locales.
|
|
1
|
+
{"version":3,"file":"getHTMLTextDir.mjs","names":[],"sources":["../../../src/localization/getHTMLTextDir.ts"],"sourcesContent":["import { Locales, type LocalesValues } from '@intlayer/types';\n\ntype Dir = 'ltr' | 'rtl' | 'auto';\n\n/**\n * Returns the text direction of the given locale.\n *\n * Example:\n *\n * getHTMLTextDir('en-US') // 'ltr'\n * getHTMLTextDir('en') // 'ltr'\n * getHTMLTextDir('fr-CA') // 'ltr'\n * getHTMLTextDir('fr') // 'ltr'\n *\n * @param locale The locale to get the text direction for.\n * @returns The text direction of the given locale.\n */\nexport const getHTMLTextDir = (locale?: LocalesValues): Dir => {\n switch (locale) {\n // Arabic (uses Arabic script)\n case Locales.ARABIC:\n case Locales.ARABIC_UNITED_ARAB_EMIRATES:\n case Locales.ARABIC_BAHRAIN:\n case Locales.ARABIC_ALGERIA:\n case Locales.ARABIC_EGYPT:\n case Locales.ARABIC_IRAQ:\n case Locales.ARABIC_JORDAN:\n case Locales.ARABIC_KUWAIT:\n case Locales.ARABIC_LEBANON:\n case Locales.ARABIC_LIBYA:\n case Locales.ARABIC_MOROCCO:\n case Locales.ARABIC_OMAN:\n case Locales.ARABIC_QATAR:\n case Locales.ARABIC_SAUDI_ARABIA:\n case Locales.ARABIC_SYRIA:\n case Locales.ARABIC_TUNISIA:\n case Locales.ARABIC_YEMEN:\n case Locales.ARABIC_MAURITANIA:\n case Locales.ARABIC_PALESTINE:\n case Locales.ARABIC_SUDAN:\n case Locales.ARABIC_DJIBOUTI:\n case Locales.ARABIC_SOMALIA:\n case Locales.ARABIC_CHAD:\n case Locales.ARABIC_COMOROS:\n // Hebrew (uses Hebrew script)\n case Locales.HEBREW:\n case Locales.HEBREW_ISRAEL:\n // Farsi/Persian (uses Arabic script)\n case Locales.FARSI:\n case Locales.FARSI_IRAN:\n // Urdu (uses Arabic script)\n case Locales.URDU:\n case Locales.URDU_ISLAMIC_REPUBLIC_OF_PAKISTAN:\n // Pashto (uses Arabic script)\n case Locales.PASHTO:\n case Locales.PASHTO_AFGHANISTAN:\n // Syriac (uses Syriac script)\n case Locales.SYRIAC:\n case Locales.SYRIAC_SYRIA:\n // Divehi (uses Thaana script)\n case Locales.DIVEHI:\n case Locales.DIVEHI_MALDIVES:\n // Yiddish (uses Hebrew script)\n case Locales.YIDDISH:\n case Locales.YIDDISH_WORLD:\n return 'rtl';\n\n default:\n return 'ltr';\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,kBAAkB,WAAgC;AAC7D,SAAQ,QAAR;EAEE,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ;EAEb,KAAK,QAAQ;EACb,KAAK,QAAQ,cACX,QAAO;EAET,QACE,QAAO"}
|