@intlayer/core 1.2.1 → 2.0.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/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs +0 -4
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +2 -3
- package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.cjs +42 -0
- package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.cjs.map +1 -0
- package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.d.ts +33 -0
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs +3 -12
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +0 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs +3 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/index.d.ts +2 -2
- package/dist/cjs/transpiler/content_transformers/index.d.ts +4 -3
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +2 -2
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs +0 -4
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +3 -3
- package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +3 -4
- package/dist/cjs/transpiler/index.d.ts +4 -3
- package/dist/cjs/types/contentModule.cjs.map +1 -1
- package/dist/cjs/types/contentModule.d.ts +2 -1
- package/dist/cjs/types/index.cjs.map +1 -1
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/keyPath.cjs +17 -0
- package/dist/cjs/types/keyPath.cjs.map +1 -0
- package/dist/cjs/types/keyPath.d.ts +13 -0
- package/dist/esm/index.d.mts +2 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +2 -3
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs +0 -6
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.d.mts +33 -0
- package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.mjs +18 -0
- package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.mjs.map +1 -0
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +0 -1
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs +3 -12
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/index.d.mts +2 -2
- package/dist/esm/transpiler/content_transformers/enumeration/index.mjs +1 -0
- package/dist/esm/transpiler/content_transformers/enumeration/index.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/index.d.mts +4 -3
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +1 -1
- package/dist/esm/transpiler/content_transformers/translation/index.d.mts +2 -2
- package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +3 -3
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs +0 -4
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/types.d.mts +3 -4
- package/dist/esm/transpiler/index.d.mts +4 -3
- package/dist/esm/types/contentModule.d.mts +2 -1
- package/dist/esm/types/index.d.mts +1 -0
- package/dist/esm/types/index.mjs.map +1 -1
- package/dist/esm/types/keyPath.d.mts +13 -0
- package/dist/esm/types/keyPath.mjs +1 -0
- package/dist/esm/types/keyPath.mjs.map +1 -0
- package/package.json +2 -3
- package/src/index.ts +4 -0
- package/src/transpiler/content_transformers/enumeration/enumeration.ts +4 -13
- package/src/transpiler/content_transformers/enumeration/findMatchingCondition.ts +64 -0
- package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +3 -31
- package/src/transpiler/content_transformers/enumeration/index.ts +1 -0
- package/src/transpiler/content_transformers/translation/translation.ts +0 -5
- package/src/transpiler/content_transformers/translation/types.ts +1 -2
- package/src/types/contentModule.ts +1 -0
- package/src/types/index.ts +5 -0
- package/src/types/keyPath.ts +13 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { QuantityContent, EnterFormat } from './enumeration.mjs';
|
|
2
|
+
import '../../../types/nodeType.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Find the matching condition for a quantity.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const key = findMatchingCondition({
|
|
11
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
12
|
+
* '<1': 'You have less than one',
|
|
13
|
+
* '2': 'You have two',
|
|
14
|
+
* '>=3': 'You have three or more',
|
|
15
|
+
* }, 2);
|
|
16
|
+
* // '2'
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* The order of the keys will define the priority of the content.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const key = findMatchingCondition({
|
|
23
|
+
* '<4': 'You have less than four',
|
|
24
|
+
* '2': 'You have two',
|
|
25
|
+
* }, 2);
|
|
26
|
+
* // '<4'
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* If no keys match, the default key is '1'.
|
|
30
|
+
*/
|
|
31
|
+
declare const findMatchingCondition: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => EnterFormat;
|
|
32
|
+
|
|
33
|
+
export { findMatchingCondition };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const findMatchingCondition = (enumerationContent, quantity) => {
|
|
2
|
+
const numericKeys = Object.keys(enumerationContent);
|
|
3
|
+
for (const key of numericKeys) {
|
|
4
|
+
const isEqual = !key.startsWith(">") && !key.startsWith("<") && !key.startsWith("=") && parseFloat(key) === quantity || key.startsWith("=") && parseFloat(key.slice(1)) === quantity;
|
|
5
|
+
const isSuperior = key.startsWith(">") && quantity > parseFloat(key.slice(1));
|
|
6
|
+
const isSuperiorOrEqual = key.startsWith(">=") && quantity >= parseFloat(key.slice(2));
|
|
7
|
+
const isInferior = key.startsWith("<") && quantity < parseFloat(key.slice(1));
|
|
8
|
+
const isInferiorOrEqual = key.startsWith("<=") && quantity <= parseFloat(key.slice(2));
|
|
9
|
+
if (isEqual || isSuperior || isSuperiorOrEqual || isInferior || isInferiorOrEqual) {
|
|
10
|
+
return key;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return "1";
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
findMatchingCondition
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=findMatchingCondition.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/findMatchingCondition.ts"],"sourcesContent":["import type { EnterFormat, QuantityContent } from './enumeration';\n\n/**\n * Find the matching condition for a quantity.\n *\n * Usage:\n *\n * ```ts\n * const key = findMatchingCondition({\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 * }, 2);\n * // '2'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const key = findMatchingCondition({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // '<4'\n * ```\n *\n * If no keys match, the default key is '1'.\n */\nexport const findMatchingCondition = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): EnterFormat => {\n const numericKeys = Object.keys(enumerationContent);\n\n for (const key of numericKeys) {\n const isEqual =\n (!key.startsWith('>') &&\n !key.startsWith('<') &&\n !key.startsWith('=') &&\n parseFloat(key) === quantity) ||\n (key.startsWith('=') && parseFloat(key.slice(1)) === quantity);\n const isSuperior =\n key.startsWith('>') && quantity > parseFloat(key.slice(1));\n const isSuperiorOrEqual =\n key.startsWith('>=') && quantity >= parseFloat(key.slice(2));\n const isInferior =\n key.startsWith('<') && quantity < parseFloat(key.slice(1));\n const isInferiorOrEqual =\n key.startsWith('<=') && quantity <= parseFloat(key.slice(2));\n\n if (\n isEqual ||\n isSuperior ||\n isSuperiorOrEqual ||\n isInferior ||\n isInferiorOrEqual\n ) {\n return key as EnterFormat;\n }\n }\n\n return '1';\n};\n"],"mappings":"AA6BO,MAAM,wBAAwB,CACnC,oBACA,aACgB;AAChB,QAAM,cAAc,OAAO,KAAK,kBAAkB;AAElD,aAAW,OAAO,aAAa;AAC7B,UAAM,UACH,CAAC,IAAI,WAAW,GAAG,KAClB,CAAC,IAAI,WAAW,GAAG,KACnB,CAAC,IAAI,WAAW,GAAG,KACnB,WAAW,GAAG,MAAM,YACrB,IAAI,WAAW,GAAG,KAAK,WAAW,IAAI,MAAM,CAAC,CAAC,MAAM;AACvD,UAAM,aACJ,IAAI,WAAW,GAAG,KAAK,WAAW,WAAW,IAAI,MAAM,CAAC,CAAC;AAC3D,UAAM,oBACJ,IAAI,WAAW,IAAI,KAAK,YAAY,WAAW,IAAI,MAAM,CAAC,CAAC;AAC7D,UAAM,aACJ,IAAI,WAAW,GAAG,KAAK,WAAW,WAAW,IAAI,MAAM,CAAC,CAAC;AAC3D,UAAM,oBACJ,IAAI,WAAW,IAAI,KAAK,YAAY,WAAW,IAAI,MAAM,CAAC,CAAC;AAE7D,QACE,WACA,cACA,qBACA,cACA,mBACA;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
+
import { findMatchingCondition } from '../../index.mjs';
|
|
1
2
|
const getEnumerationContent = (enumerationContent, quantity) => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const isEqual = !key.startsWith(">") && !key.startsWith("<") && !key.startsWith("=") && parseFloat(key) === quantity || key.startsWith("=") && parseFloat(key.slice(1)) === quantity;
|
|
5
|
-
const isSuperior = key.startsWith(">") && quantity > parseFloat(key.slice(1));
|
|
6
|
-
const isSuperiorOrEqual = key.startsWith(">=") && quantity >= parseFloat(key.slice(2));
|
|
7
|
-
const isInferior = key.startsWith("<") && quantity < parseFloat(key.slice(1));
|
|
8
|
-
const isInferiorOrEqual = key.startsWith("<=") && quantity <= parseFloat(key.slice(2));
|
|
9
|
-
if (isEqual || isSuperior || isSuperiorOrEqual || isInferior || isInferiorOrEqual) {
|
|
10
|
-
return enumerationContent[key];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return enumerationContent["1"];
|
|
3
|
+
const key = findMatchingCondition(enumerationContent, quantity);
|
|
4
|
+
return enumerationContent[key];
|
|
14
5
|
};
|
|
15
6
|
export {
|
|
16
7
|
getEnumerationContent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/getEnumerationContent.ts"],"sourcesContent":["import type { QuantityContent } from './enumeration';\n\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/getEnumerationContent.ts"],"sourcesContent":["import { findMatchingCondition } from '../..';\nimport type { QuantityContent } from './enumeration';\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\n * ```ts\n * const content = getEnumerationContent({\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 * }, 2);\n * // 'You have two'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const content = getEnumerationContent({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // 'You have less than four'\n * ```\n *\n */\nexport const getEnumerationContent = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const key = findMatchingCondition<Content>(enumerationContent, quantity);\n\n // Default or error handling if no keys match\n return enumerationContent[key];\n};\n"],"mappings":"AAAA,SAAS,6BAA6B;AA6B/B,MAAM,wBAAwB,CACnC,oBACA,aACY;AACZ,QAAM,MAAM,sBAA+B,oBAAoB,QAAQ;AAGvE,SAAO,mBAAmB,GAAG;AAC/B;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { EnumerationContent, QuantityContent, enu } from './enumeration.mjs';
|
|
1
|
+
export { EnterFormat, EnumerationContent, QuantityContent, enu } from './enumeration.mjs';
|
|
2
2
|
export { getEnumerationContent } from './getEnumerationContent.mjs';
|
|
3
|
-
|
|
3
|
+
export { findMatchingCondition } from './findMatchingCondition.mjs';
|
|
4
4
|
import '../../../types/nodeType.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/index.ts"],"sourcesContent":["export * from './enumeration';\nexport * from './getEnumerationContent';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/index.ts"],"sourcesContent":["export * from './enumeration';\nexport * from './getEnumerationContent';\nexport * from './findMatchingCondition';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { t } from './translation/translation.mjs';
|
|
2
2
|
export { getTranslationContent } from './translation/getTranslationContent.mjs';
|
|
3
|
-
export {
|
|
4
|
-
export { EnumerationContent, QuantityContent, enu } from './enumeration/enumeration.mjs';
|
|
3
|
+
export { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './translation/types.mjs';
|
|
4
|
+
export { EnterFormat, EnumerationContent, QuantityContent, enu } from './enumeration/enumeration.mjs';
|
|
5
5
|
export { getEnumerationContent } from './enumeration/getEnumerationContent.mjs';
|
|
6
|
+
export { findMatchingCondition } from './enumeration/findMatchingCondition.mjs';
|
|
6
7
|
import '@intlayer/config/client';
|
|
7
8
|
import 'intlayer';
|
|
8
|
-
import '../../utils/getStackTraceInfo.mjs';
|
|
9
9
|
import '../../types/nodeType.mjs';
|
|
10
|
+
import '../../utils/getStackTraceInfo.mjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Locales } from '@intlayer/config/client';
|
|
2
2
|
import { CustomizableLanguageContent } from './types.mjs';
|
|
3
3
|
import 'intlayer';
|
|
4
|
-
import '../../../utils/getStackTraceInfo.mjs';
|
|
5
4
|
import '../../../types/nodeType.mjs';
|
|
5
|
+
import '../../../utils/getStackTraceInfo.mjs';
|
|
6
6
|
|
|
7
7
|
type GetTranslationContent = <Content = string>(languageContent: CustomizableLanguageContent<Content>, locale: Locales) => Content;
|
|
8
8
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { t } from './translation.mjs';
|
|
2
2
|
export { getTranslationContent } from './getTranslationContent.mjs';
|
|
3
|
-
export {
|
|
3
|
+
export { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './types.mjs';
|
|
4
4
|
import '@intlayer/config/client';
|
|
5
5
|
import 'intlayer';
|
|
6
|
-
import '../../../utils/getStackTraceInfo.mjs';
|
|
7
6
|
import '../../../types/nodeType.mjs';
|
|
7
|
+
import '../../../utils/getStackTraceInfo.mjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TranslationContent } from './types.mjs';
|
|
2
2
|
import '@intlayer/config/client';
|
|
3
3
|
import 'intlayer';
|
|
4
|
-
import '../../../utils/getStackTraceInfo.mjs';
|
|
5
4
|
import '../../../types/nodeType.mjs';
|
|
5
|
+
import '../../../utils/getStackTraceInfo.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -24,6 +24,6 @@ import '../../../types/nodeType.mjs';
|
|
|
24
24
|
* - this function require each locale to be defined if defined in the project configuration.
|
|
25
25
|
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
26
26
|
*/
|
|
27
|
-
declare const translation: <Content = string>(content?:
|
|
27
|
+
declare const translation: <Content = string>(content?: any) => TranslationContent<Content>;
|
|
28
28
|
|
|
29
29
|
export { translation as t };
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import { getConfiguration } from "@intlayer/config/client";
|
|
2
2
|
import { NodeType } from '../../../types/index.mjs';
|
|
3
|
-
import { getStackTraceInfo } from '../../../utils/getStackTraceInfo.mjs';
|
|
4
3
|
const translation = (content) => {
|
|
5
4
|
const {
|
|
6
5
|
internationalization: { defaultLocale }
|
|
7
6
|
} = getConfiguration();
|
|
8
|
-
const stackTraceInfo = getStackTraceInfo();
|
|
9
7
|
if (typeof content === "string") {
|
|
10
8
|
const result2 = {
|
|
11
9
|
nodeType: NodeType.Translation,
|
|
12
|
-
...stackTraceInfo,
|
|
13
10
|
[defaultLocale]: content
|
|
14
11
|
};
|
|
15
12
|
return result2;
|
|
16
13
|
}
|
|
17
14
|
const result = {
|
|
18
15
|
nodeType: NodeType.Translation,
|
|
19
|
-
...stackTraceInfo,
|
|
20
16
|
...content
|
|
21
17
|
};
|
|
22
18
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport type { CustomizableLanguageContent, TranslationContent } from './types';\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 = <Content = string>(\n content?: CustomizableLanguageContent<Content>\n) => {\n const {\n internationalization: { defaultLocale },\n } = getConfiguration();\n\n if (typeof content === 'string') {\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n [defaultLocale]: content,\n } as TranslationContent<Content>;\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...(content as unknown as object),\n } as TranslationContent<Content>;\n\n return result;\n};\n\nexport { translation as t };\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAAS,gBAAgB;AAuBzB,MAAM,cAAc,CAClB,YACG;AACH,QAAM;AAAA,IACJ,sBAAsB,EAAE,cAAc;AAAA,EACxC,IAAI,iBAAiB;AAErB,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,SAAS;AAAA,MACnB,CAAC,aAAa,GAAG;AAAA,IACnB;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,GAAI;AAAA,EACN;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LocalesValues } from '@intlayer/config/client';
|
|
2
2
|
import { IConfigLocales } from 'intlayer';
|
|
3
|
-
import { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo.mjs';
|
|
4
3
|
import { NodeType } from '../../../types/nodeType.mjs';
|
|
4
|
+
import { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...
|
|
@@ -27,7 +27,6 @@ type CustomLocales = ConfigLocales extends never ? LocalesValues : ConfigLocales
|
|
|
27
27
|
* }
|
|
28
28
|
*/
|
|
29
29
|
type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;
|
|
30
|
-
type ConfigLanguageContent<Content> = Record<ConfigLocales, Content>;
|
|
31
30
|
/**
|
|
32
31
|
* Valid
|
|
33
32
|
* const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {
|
|
@@ -55,9 +54,9 @@ type ConfigLanguageContent<Content> = Record<ConfigLocales, Content>;
|
|
|
55
54
|
* }
|
|
56
55
|
*
|
|
57
56
|
*/
|
|
58
|
-
type CustomizableLanguageContent<Content = string> = ConfigLocales extends never ? LanguageContent<Content> :
|
|
57
|
+
type CustomizableLanguageContent<Content = string> = ConfigLocales extends never ? LanguageContent<Content> : IConfigLocales<Content>;
|
|
59
58
|
type TranslationContent<Content> = LanguageContent<Content> & NoteStackTraceInfo & {
|
|
60
59
|
nodeType: NodeType.Translation;
|
|
61
60
|
};
|
|
62
61
|
|
|
63
|
-
export type {
|
|
62
|
+
export type { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { t } from './content_transformers/translation/translation.mjs';
|
|
2
2
|
export { getTranslationContent } from './content_transformers/translation/getTranslationContent.mjs';
|
|
3
|
-
export {
|
|
4
|
-
export { EnumerationContent, QuantityContent, enu } from './content_transformers/enumeration/enumeration.mjs';
|
|
3
|
+
export { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './content_transformers/translation/types.mjs';
|
|
4
|
+
export { EnterFormat, EnumerationContent, QuantityContent, enu } from './content_transformers/enumeration/enumeration.mjs';
|
|
5
5
|
export { getEnumerationContent } from './content_transformers/enumeration/getEnumerationContent.mjs';
|
|
6
|
+
export { findMatchingCondition } from './content_transformers/enumeration/findMatchingCondition.mjs';
|
|
6
7
|
import '@intlayer/config/client';
|
|
7
8
|
import 'intlayer';
|
|
8
|
-
import '../utils/getStackTraceInfo.mjs';
|
|
9
9
|
import '../types/nodeType.mjs';
|
|
10
|
+
import '../utils/getStackTraceInfo.mjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TranslationContent } from '../transpiler/content_transformers/translation/types.mjs';
|
|
2
2
|
import { EnumerationContent } from '../transpiler/content_transformers/enumeration/enumeration.mjs';
|
|
3
|
-
import './nodeType.mjs';
|
|
4
3
|
import '@intlayer/config/client';
|
|
5
4
|
import 'intlayer';
|
|
5
|
+
import './nodeType.mjs';
|
|
6
6
|
import '../utils/getStackTraceInfo.mjs';
|
|
7
7
|
|
|
8
8
|
type TypedNode = TranslationContent<unknown> | EnumerationContent<unknown>;
|
|
@@ -16,6 +16,7 @@ type FlatContentValue = string | {
|
|
|
16
16
|
type FlatContent = Record<string, FlatContentValue | undefined>;
|
|
17
17
|
type ContentModule = Content & {
|
|
18
18
|
id: string;
|
|
19
|
+
filePath?: string;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export type { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode } from './contentModule.mjs';
|
|
2
2
|
export { NodeType } from './nodeType.mjs';
|
|
3
|
+
export { KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './keyPath.mjs';
|
|
3
4
|
import '../transpiler/content_transformers/translation/types.mjs';
|
|
4
5
|
import '@intlayer/config/client';
|
|
5
6
|
import 'intlayer';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n ContentModule,\n} from './contentModule';\nexport { NodeType } from './nodeType';\n"],"mappings":"AAQA,SAAS,gBAAgB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n ContentModule,\n} from './contentModule';\nexport { NodeType } from './nodeType';\nexport type {\n KeyPath,\n ObjectExpressionNode,\n TranslationOrEnumerationNode,\n} from './keyPath';\n"],"mappings":"AAQA,SAAS,gBAAgB;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NodeType } from './nodeType.mjs';
|
|
2
|
+
|
|
3
|
+
type ObjectExpressionNode = {
|
|
4
|
+
type: 'ObjectExpression';
|
|
5
|
+
key: string;
|
|
6
|
+
};
|
|
7
|
+
type TranslationOrEnumerationNode = {
|
|
8
|
+
type: NodeType;
|
|
9
|
+
key: string;
|
|
10
|
+
};
|
|
11
|
+
type KeyPath = ObjectExpressionNode | TranslationOrEnumerationNode;
|
|
12
|
+
|
|
13
|
+
export type { KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=keyPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "IntLayer - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
|
|
6
6
|
"keywords": [
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"chokidar": "^3.6.0",
|
|
54
|
-
"@intlayer/config": "^
|
|
54
|
+
"@intlayer/config": "^2.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^20.12.7",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"@utils/ts-config": "^1.0.1"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@types/react": "^18.2.78",
|
|
68
67
|
"react": "^18.2.0"
|
|
69
68
|
},
|
|
70
69
|
"engines": {
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export {
|
|
|
10
10
|
t,
|
|
11
11
|
enu,
|
|
12
12
|
getTranslationContent,
|
|
13
|
+
findMatchingCondition,
|
|
13
14
|
getEnumerationContent,
|
|
14
15
|
} from './transpiler/content_transformers/index';
|
|
15
16
|
export type {
|
|
@@ -19,6 +20,9 @@ export type {
|
|
|
19
20
|
FlatContent,
|
|
20
21
|
TypedNode,
|
|
21
22
|
ContentModule,
|
|
23
|
+
KeyPath,
|
|
24
|
+
ObjectExpressionNode,
|
|
25
|
+
TranslationOrEnumerationNode,
|
|
22
26
|
} from './types/index';
|
|
23
27
|
export { NodeType } from './types/index';
|
|
24
28
|
export { getLocaleName } from './getLocaleName';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import { NodeType } from '../../../types/index';
|
|
3
|
-
import {
|
|
4
|
-
getStackTraceInfo,
|
|
5
|
-
type NoteStackTraceInfo,
|
|
6
|
-
} from '../../../utils/getStackTraceInfo';
|
|
7
3
|
|
|
8
4
|
type Positif = number | `${number}`;
|
|
9
5
|
type Negatif = `-${number}`;
|
|
@@ -16,7 +12,7 @@ type SuperiorOrEqual = `>=${Numbers}`;
|
|
|
16
12
|
type Inferior = `<${Numbers}`;
|
|
17
13
|
type InferiorOrEqual = `<=${Numbers}`;
|
|
18
14
|
|
|
19
|
-
type EnterFormat =
|
|
15
|
+
export type EnterFormat =
|
|
20
16
|
| Equal
|
|
21
17
|
| EqualString
|
|
22
18
|
| Superior
|
|
@@ -26,10 +22,9 @@ type EnterFormat =
|
|
|
26
22
|
|
|
27
23
|
export type QuantityContent<Content> = Record<EnterFormat, Content>;
|
|
28
24
|
|
|
29
|
-
export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
25
|
+
export type EnumerationContent<Content> = Partial<QuantityContent<Content>> & {
|
|
26
|
+
nodeType: NodeType.Enumeration;
|
|
27
|
+
};
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
30
|
* Function intended to be used to build intlayer dictionaries.
|
|
@@ -51,12 +46,9 @@ export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
|
51
46
|
*
|
|
52
47
|
*/
|
|
53
48
|
const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
|
|
54
|
-
const stackTraceInfo = getStackTraceInfo();
|
|
55
|
-
|
|
56
49
|
if (typeof content === 'string') {
|
|
57
50
|
const result: EnumerationContent<Content> = {
|
|
58
51
|
nodeType: NodeType.Enumeration,
|
|
59
|
-
...stackTraceInfo,
|
|
60
52
|
1: content,
|
|
61
53
|
};
|
|
62
54
|
|
|
@@ -65,7 +57,6 @@ const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
|
|
|
65
57
|
|
|
66
58
|
const result: EnumerationContent<Content> = {
|
|
67
59
|
nodeType: NodeType.Enumeration,
|
|
68
|
-
...stackTraceInfo,
|
|
69
60
|
...content,
|
|
70
61
|
};
|
|
71
62
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { EnterFormat, QuantityContent } from './enumeration';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Find the matching condition for a quantity.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const key = findMatchingCondition({
|
|
10
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
11
|
+
* '<1': 'You have less than one',
|
|
12
|
+
* '2': 'You have two',
|
|
13
|
+
* '>=3': 'You have three or more',
|
|
14
|
+
* }, 2);
|
|
15
|
+
* // '2'
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* The order of the keys will define the priority of the content.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const key = findMatchingCondition({
|
|
22
|
+
* '<4': 'You have less than four',
|
|
23
|
+
* '2': 'You have two',
|
|
24
|
+
* }, 2);
|
|
25
|
+
* // '<4'
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* If no keys match, the default key is '1'.
|
|
29
|
+
*/
|
|
30
|
+
export const findMatchingCondition = <Content>(
|
|
31
|
+
enumerationContent: QuantityContent<Content>,
|
|
32
|
+
quantity: number
|
|
33
|
+
): EnterFormat => {
|
|
34
|
+
const numericKeys = Object.keys(enumerationContent);
|
|
35
|
+
|
|
36
|
+
for (const key of numericKeys) {
|
|
37
|
+
const isEqual =
|
|
38
|
+
(!key.startsWith('>') &&
|
|
39
|
+
!key.startsWith('<') &&
|
|
40
|
+
!key.startsWith('=') &&
|
|
41
|
+
parseFloat(key) === quantity) ||
|
|
42
|
+
(key.startsWith('=') && parseFloat(key.slice(1)) === quantity);
|
|
43
|
+
const isSuperior =
|
|
44
|
+
key.startsWith('>') && quantity > parseFloat(key.slice(1));
|
|
45
|
+
const isSuperiorOrEqual =
|
|
46
|
+
key.startsWith('>=') && quantity >= parseFloat(key.slice(2));
|
|
47
|
+
const isInferior =
|
|
48
|
+
key.startsWith('<') && quantity < parseFloat(key.slice(1));
|
|
49
|
+
const isInferiorOrEqual =
|
|
50
|
+
key.startsWith('<=') && quantity <= parseFloat(key.slice(2));
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
isEqual ||
|
|
54
|
+
isSuperior ||
|
|
55
|
+
isSuperiorOrEqual ||
|
|
56
|
+
isInferior ||
|
|
57
|
+
isInferiorOrEqual
|
|
58
|
+
) {
|
|
59
|
+
return key as EnterFormat;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return '1';
|
|
64
|
+
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { findMatchingCondition } from '../..';
|
|
1
2
|
import type { QuantityContent } from './enumeration';
|
|
2
3
|
|
|
3
|
-
type Key = keyof QuantityContent<string>;
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Allow to pick a content based on a quantity.
|
|
7
6
|
*
|
|
@@ -32,35 +31,8 @@ export const getEnumerationContent = <Content>(
|
|
|
32
31
|
enumerationContent: QuantityContent<Content>,
|
|
33
32
|
quantity: number
|
|
34
33
|
): Content => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
for (const key of numericKeys) {
|
|
38
|
-
const isEqual =
|
|
39
|
-
(!key.startsWith('>') &&
|
|
40
|
-
!key.startsWith('<') &&
|
|
41
|
-
!key.startsWith('=') &&
|
|
42
|
-
parseFloat(key) === quantity) ||
|
|
43
|
-
(key.startsWith('=') && parseFloat(key.slice(1)) === quantity);
|
|
44
|
-
const isSuperior =
|
|
45
|
-
key.startsWith('>') && quantity > parseFloat(key.slice(1));
|
|
46
|
-
const isSuperiorOrEqual =
|
|
47
|
-
key.startsWith('>=') && quantity >= parseFloat(key.slice(2));
|
|
48
|
-
const isInferior =
|
|
49
|
-
key.startsWith('<') && quantity < parseFloat(key.slice(1));
|
|
50
|
-
const isInferiorOrEqual =
|
|
51
|
-
key.startsWith('<=') && quantity <= parseFloat(key.slice(2));
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
isEqual ||
|
|
55
|
-
isSuperior ||
|
|
56
|
-
isSuperiorOrEqual ||
|
|
57
|
-
isInferior ||
|
|
58
|
-
isInferiorOrEqual
|
|
59
|
-
) {
|
|
60
|
-
return enumerationContent[key as Key];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
34
|
+
const key = findMatchingCondition<Content>(enumerationContent, quantity);
|
|
63
35
|
|
|
64
36
|
// Default or error handling if no keys match
|
|
65
|
-
return enumerationContent[
|
|
37
|
+
return enumerationContent[key];
|
|
66
38
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getConfiguration } from '@intlayer/config/client';
|
|
2
2
|
import { NodeType } from '../../../types/index';
|
|
3
|
-
import { getStackTraceInfo } from '../../../utils/getStackTraceInfo';
|
|
4
3
|
import type { CustomizableLanguageContent, TranslationContent } from './types';
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -30,12 +29,9 @@ const translation = <Content = string>(
|
|
|
30
29
|
internationalization: { defaultLocale },
|
|
31
30
|
} = getConfiguration();
|
|
32
31
|
|
|
33
|
-
const stackTraceInfo = getStackTraceInfo();
|
|
34
|
-
|
|
35
32
|
if (typeof content === 'string') {
|
|
36
33
|
const result: TranslationContent<Content> = {
|
|
37
34
|
nodeType: NodeType.Translation,
|
|
38
|
-
...stackTraceInfo,
|
|
39
35
|
[defaultLocale]: content,
|
|
40
36
|
} as TranslationContent<Content>;
|
|
41
37
|
|
|
@@ -44,7 +40,6 @@ const translation = <Content = string>(
|
|
|
44
40
|
|
|
45
41
|
const result: TranslationContent<Content> = {
|
|
46
42
|
nodeType: NodeType.Translation,
|
|
47
|
-
...stackTraceInfo,
|
|
48
43
|
...(content as unknown as object),
|
|
49
44
|
} as TranslationContent<Content>;
|
|
50
45
|
|
|
@@ -32,7 +32,6 @@ export type CustomLocales = ConfigLocales extends never
|
|
|
32
32
|
* }
|
|
33
33
|
*/
|
|
34
34
|
export type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;
|
|
35
|
-
export type ConfigLanguageContent<Content> = Record<ConfigLocales, Content>;
|
|
36
35
|
|
|
37
36
|
/**
|
|
38
37
|
* Valid
|
|
@@ -64,7 +63,7 @@ export type ConfigLanguageContent<Content> = Record<ConfigLocales, Content>;
|
|
|
64
63
|
export type CustomizableLanguageContent<Content = string> =
|
|
65
64
|
ConfigLocales extends never
|
|
66
65
|
? LanguageContent<Content>
|
|
67
|
-
:
|
|
66
|
+
: IConfigLocales<Content>;
|
|
68
67
|
|
|
69
68
|
export type TranslationContent<Content> = LanguageContent<Content> &
|
|
70
69
|
NoteStackTraceInfo & {
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NodeType } from './nodeType';
|
|
2
|
+
|
|
3
|
+
export type ObjectExpressionNode = {
|
|
4
|
+
type: 'ObjectExpression';
|
|
5
|
+
key: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type TranslationOrEnumerationNode = {
|
|
9
|
+
type: NodeType;
|
|
10
|
+
key: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type KeyPath = ObjectExpressionNode | TranslationOrEnumerationNode;
|