@intlayer/core 1.2.0 → 1.2.1
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/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +2 -0
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +8 -5
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +5 -4
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs +3 -1
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +2 -0
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +2 -0
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +8 -5
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +5 -4
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs +2 -4
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +2 -0
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs +4 -2
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -1
- package/package.json +2 -2
- package/src/transpiler/content_transformers/enumeration/enumeration.ts +2 -0
- package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +8 -5
- package/src/transpiler/content_transformers/translation/getTranslationContent.ts +7 -9
- package/src/transpiler/content_transformers/translation/translation.ts +7 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/enumeration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NodeType } from '../../../types/index';\nimport {\n getStackTraceInfo,\n type NoteStackTraceInfo,\n} from '../../../utils/getStackTraceInfo';\n\ntype Positif = number | `${number}`;\ntype Negatif = `-${number}`;\ntype Numbers = Positif | Negatif;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\ntype EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type QuantityContent<Content> = Record<EnterFormat, Content>;\n\nexport type EnumerationContent<Content> = Partial<QuantityContent<Content>> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Enumeration;\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 * const content = 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 * The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {\n const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n 1: content,\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n ...content,\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyB;AACzB,+BAGO;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/enumeration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NodeType } from '../../../types/index';\nimport {\n getStackTraceInfo,\n type NoteStackTraceInfo,\n} from '../../../utils/getStackTraceInfo';\n\ntype Positif = number | `${number}`;\ntype Negatif = `-${number}`;\ntype Numbers = Positif | Negatif;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\ntype EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type QuantityContent<Content> = Record<EnterFormat, Content>;\n\nexport type EnumerationContent<Content> = Partial<QuantityContent<Content>> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Enumeration;\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 * const content = 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?: Partial<QuantityContent<Content>>) => {\n const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n 1: content,\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n ...content,\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyB;AACzB,+BAGO;AA+CP,MAAM,cAAc,CAAU,YAAgD;AAC5E,QAAM,qBAAiB,4CAAkB;AAEzC,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,sBAAS;AAAA,MACnB,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -22,12 +22,14 @@ type EnumerationContent<Content> = Partial<QuantityContent<Content>> & NoteStack
|
|
|
22
22
|
*
|
|
23
23
|
* Usage:
|
|
24
24
|
*
|
|
25
|
+
* ```ts
|
|
25
26
|
* const content = enu({
|
|
26
27
|
* '<=-2.3': 'You have less than -2.3',
|
|
27
28
|
* '<1': 'You have less than one',
|
|
28
29
|
* '2': 'You have two',
|
|
29
30
|
* '>=3': 'You have three or more',
|
|
30
31
|
* });
|
|
32
|
+
* ```
|
|
31
33
|
*
|
|
32
34
|
* The order of the keys will define the priority of the content.
|
|
33
35
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/getEnumerationContent.ts"],"sourcesContent":["import type { QuantityContent } from './enumeration';\n\ntype Key = keyof QuantityContent<string>;\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\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 * }
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/getEnumerationContent.ts"],"sourcesContent":["import type { QuantityContent } from './enumeration';\n\ntype Key = keyof QuantityContent<string>;\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 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 enumerationContent[key as Key];\n }\n }\n\n // Default or error handling if no keys match\n return enumerationContent['1'];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,MAAM,wBAAwB,CACnC,oBACA,aACY;AACZ,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,mBAAmB,GAAU;AAAA,IACtC;AAAA,EACF;AAGA,SAAO,mBAAmB,GAAG;AAC/B;","names":[]}
|
|
@@ -7,22 +7,25 @@ import '../../../types/nodeType.js';
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* const content = getEnumerationContent({
|
|
11
12
|
* '<=-2.3': 'You have less than -2.3',
|
|
12
13
|
* '<1': 'You have less than one',
|
|
13
14
|
* '2': 'You have two',
|
|
14
15
|
* '>=3': 'You have three or more',
|
|
15
|
-
* },
|
|
16
|
-
* 2);
|
|
16
|
+
* }, 2);
|
|
17
17
|
* // 'You have two'
|
|
18
|
+
* ```
|
|
18
19
|
*
|
|
19
20
|
* The order of the keys will define the priority of the content.
|
|
20
21
|
*
|
|
22
|
+
* ```ts
|
|
21
23
|
* const content = getEnumerationContent({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* });
|
|
24
|
+
* '<4': 'You have less than four',
|
|
25
|
+
* '2': 'You have two',
|
|
26
|
+
* }, 2);
|
|
25
27
|
* // 'You have less than four'
|
|
28
|
+
* ```
|
|
26
29
|
*
|
|
27
30
|
*/
|
|
28
31
|
declare const getEnumerationContent: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
@@ -22,7 +22,7 @@ __export(getTranslationContent_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getTranslationContent_exports);
|
|
24
24
|
var import_client = require("@intlayer/config/client");
|
|
25
|
-
const defaultLocale = import_client.
|
|
25
|
+
const defaultLocale = (0, import_client.getConfiguration)().internationalization.defaultLocale;
|
|
26
26
|
const getTranslationContent = (languageContent, locale) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
|
|
27
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
28
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { CustomizableLanguageContent } from './types';\n\nconst defaultLocale = getConfiguration().internationalization.defaultLocale;\n\ntype GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => Content;\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslationContent({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslationContent: GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAG/C,MAAM,oBAAgB,gCAAiB,EAAE,qBAAqB;AA0BvD,MAAM,wBAA+C,CAC1D,iBACA,WACG,gBAAgB,UAAU,aAAa,KAAK,gBAAgB,aAAa;","names":[]}
|
|
@@ -12,12 +12,13 @@ type GetTranslationContent = <Content = string>(languageContent: CustomizableLan
|
|
|
12
12
|
*
|
|
13
13
|
* Usage:
|
|
14
14
|
*
|
|
15
|
+
* ```ts
|
|
15
16
|
* const content = getTranslationContent({
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* },
|
|
19
|
-
* 'fr');
|
|
17
|
+
* en: 'Hello',
|
|
18
|
+
* fr: 'Bonjour',
|
|
19
|
+
* }, 'fr');
|
|
20
20
|
* // 'Bonjour'
|
|
21
|
+
* ```
|
|
21
22
|
*
|
|
22
23
|
* Using TypeScript:
|
|
23
24
|
* - this function will require each locale to be defined if defined in the project configuration.
|
|
@@ -24,8 +24,10 @@ module.exports = __toCommonJS(translation_exports);
|
|
|
24
24
|
var import_client = require("@intlayer/config/client");
|
|
25
25
|
var import_types = require('../../../types/index.cjs');
|
|
26
26
|
var import_getStackTraceInfo = require('../../../utils/getStackTraceInfo.cjs');
|
|
27
|
-
const { defaultLocale } = import_client.intlayerConfiguration.internationalization;
|
|
28
27
|
const translation = (content) => {
|
|
28
|
+
const {
|
|
29
|
+
internationalization: { defaultLocale }
|
|
30
|
+
} = (0, import_client.getConfiguration)();
|
|
29
31
|
const stackTraceInfo = (0, import_getStackTraceInfo.getStackTraceInfo)();
|
|
30
32
|
if (typeof content === "string") {
|
|
31
33
|
const result2 = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport { getStackTraceInfo } from '../../../utils/getStackTraceInfo';\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 const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n [defaultLocale]: content,\n } as TranslationContent<Content>;\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n ...(content as unknown as object),\n } as TranslationContent<Content>;\n\n return result;\n};\n\nexport { translation as t };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,mBAAyB;AACzB,+BAAkC;AAuBlC,MAAM,cAAc,CAClB,YACG;AACH,QAAM;AAAA,IACJ,sBAAsB,EAAE,cAAc;AAAA,EACxC,QAAI,gCAAiB;AAErB,QAAM,qBAAiB,4CAAkB;AAEzC,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,sBAAS;AAAA,MACnB,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,IACnB;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,GAAG;AAAA,IACH,GAAI;AAAA,EACN;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -12,11 +12,13 @@ import '../../../types/nodeType.js';
|
|
|
12
12
|
*
|
|
13
13
|
* Usage:
|
|
14
14
|
*
|
|
15
|
+
* ```ts
|
|
15
16
|
* translation<string>({
|
|
16
17
|
* "en": "Hello",
|
|
17
18
|
* "fr": "Bonjour",
|
|
18
19
|
* // ... any other available locale
|
|
19
20
|
* })
|
|
21
|
+
* ```
|
|
20
22
|
*
|
|
21
23
|
* Using TypeScript:
|
|
22
24
|
* - this function require each locale to be defined if defined in the project configuration.
|
|
@@ -22,12 +22,14 @@ type EnumerationContent<Content> = Partial<QuantityContent<Content>> & NoteStack
|
|
|
22
22
|
*
|
|
23
23
|
* Usage:
|
|
24
24
|
*
|
|
25
|
+
* ```ts
|
|
25
26
|
* const content = enu({
|
|
26
27
|
* '<=-2.3': 'You have less than -2.3',
|
|
27
28
|
* '<1': 'You have less than one',
|
|
28
29
|
* '2': 'You have two',
|
|
29
30
|
* '>=3': 'You have three or more',
|
|
30
31
|
* });
|
|
32
|
+
* ```
|
|
31
33
|
*
|
|
32
34
|
* The order of the keys will define the priority of the content.
|
|
33
35
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/enumeration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NodeType } from '../../../types/index';\nimport {\n getStackTraceInfo,\n type NoteStackTraceInfo,\n} from '../../../utils/getStackTraceInfo';\n\ntype Positif = number | `${number}`;\ntype Negatif = `-${number}`;\ntype Numbers = Positif | Negatif;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\ntype EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type QuantityContent<Content> = Record<EnterFormat, Content>;\n\nexport type EnumerationContent<Content> = Partial<QuantityContent<Content>> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Enumeration;\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 * const content = 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 * The order of the keys will define the priority of the content.\n *\n */\nconst enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {\n const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n 1: content,\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n ...content,\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":"AACA,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,OAEK;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/enumeration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NodeType } from '../../../types/index';\nimport {\n getStackTraceInfo,\n type NoteStackTraceInfo,\n} from '../../../utils/getStackTraceInfo';\n\ntype Positif = number | `${number}`;\ntype Negatif = `-${number}`;\ntype Numbers = Positif | Negatif;\n\ntype Equal = Numbers;\ntype EqualString = `=${Numbers}`;\ntype Superior = `>${Numbers}`;\ntype SuperiorOrEqual = `>=${Numbers}`;\ntype Inferior = `<${Numbers}`;\ntype InferiorOrEqual = `<=${Numbers}`;\n\ntype EnterFormat =\n | Equal\n | EqualString\n | Superior\n | SuperiorOrEqual\n | Inferior\n | InferiorOrEqual;\n\nexport type QuantityContent<Content> = Record<EnterFormat, Content>;\n\nexport type EnumerationContent<Content> = Partial<QuantityContent<Content>> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Enumeration;\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 * const content = 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?: Partial<QuantityContent<Content>>) => {\n const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n 1: content,\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...stackTraceInfo,\n ...content,\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":"AACA,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,OAEK;AA+CP,MAAM,cAAc,CAAU,YAAgD;AAC5E,QAAM,iBAAiB,kBAAkB;AAEzC,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,SAAS;AAAA,MACnB,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -7,22 +7,25 @@ import '../../../types/nodeType.mjs';
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* const content = getEnumerationContent({
|
|
11
12
|
* '<=-2.3': 'You have less than -2.3',
|
|
12
13
|
* '<1': 'You have less than one',
|
|
13
14
|
* '2': 'You have two',
|
|
14
15
|
* '>=3': 'You have three or more',
|
|
15
|
-
* },
|
|
16
|
-
* 2);
|
|
16
|
+
* }, 2);
|
|
17
17
|
* // 'You have two'
|
|
18
|
+
* ```
|
|
18
19
|
*
|
|
19
20
|
* The order of the keys will define the priority of the content.
|
|
20
21
|
*
|
|
22
|
+
* ```ts
|
|
21
23
|
* const content = getEnumerationContent({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* });
|
|
24
|
+
* '<4': 'You have less than four',
|
|
25
|
+
* '2': 'You have two',
|
|
26
|
+
* }, 2);
|
|
25
27
|
* // 'You have less than four'
|
|
28
|
+
* ```
|
|
26
29
|
*
|
|
27
30
|
*/
|
|
28
31
|
declare const getEnumerationContent: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/getEnumerationContent.ts"],"sourcesContent":["import type { QuantityContent } from './enumeration';\n\ntype Key = keyof QuantityContent<string>;\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Usage:\n *\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 * }
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/getEnumerationContent.ts"],"sourcesContent":["import type { QuantityContent } from './enumeration';\n\ntype Key = keyof QuantityContent<string>;\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 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 enumerationContent[key as Key];\n }\n }\n\n // Default or error handling if no keys match\n return enumerationContent['1'];\n};\n"],"mappings":"AA8BO,MAAM,wBAAwB,CACnC,oBACA,aACY;AACZ,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,mBAAmB,GAAU;AAAA,IACtC;AAAA,EACF;AAGA,SAAO,mBAAmB,GAAG;AAC/B;","names":[]}
|
|
@@ -12,12 +12,13 @@ type GetTranslationContent = <Content = string>(languageContent: CustomizableLan
|
|
|
12
12
|
*
|
|
13
13
|
* Usage:
|
|
14
14
|
*
|
|
15
|
+
* ```ts
|
|
15
16
|
* const content = getTranslationContent({
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* },
|
|
19
|
-
* 'fr');
|
|
17
|
+
* en: 'Hello',
|
|
18
|
+
* fr: 'Bonjour',
|
|
19
|
+
* }, 'fr');
|
|
20
20
|
* // 'Bonjour'
|
|
21
|
+
* ```
|
|
21
22
|
*
|
|
22
23
|
* Using TypeScript:
|
|
23
24
|
* - this function will require each locale to be defined if defined in the project configuration.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "@intlayer/config/client";
|
|
4
|
-
const defaultLocale = intlayerIntlConfiguration.defaultLocale;
|
|
1
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
2
|
+
const defaultLocale = getConfiguration().internationalization.defaultLocale;
|
|
5
3
|
const getTranslationContent = (languageContent, locale) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];
|
|
6
4
|
export {
|
|
7
5
|
getTranslationContent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { CustomizableLanguageContent } from './types';\n\nconst defaultLocale = getConfiguration().internationalization.defaultLocale;\n\ntype GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => Content;\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslationContent({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslationContent: GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAG/C,MAAM,gBAAgB,iBAAiB,EAAE,qBAAqB;AA0BvD,MAAM,wBAA+C,CAC1D,iBACA,WACG,gBAAgB,UAAU,aAAa,KAAK,gBAAgB,aAAa;","names":[]}
|
|
@@ -12,11 +12,13 @@ import '../../../types/nodeType.mjs';
|
|
|
12
12
|
*
|
|
13
13
|
* Usage:
|
|
14
14
|
*
|
|
15
|
+
* ```ts
|
|
15
16
|
* translation<string>({
|
|
16
17
|
* "en": "Hello",
|
|
17
18
|
* "fr": "Bonjour",
|
|
18
19
|
* // ... any other available locale
|
|
19
20
|
* })
|
|
21
|
+
* ```
|
|
20
22
|
*
|
|
21
23
|
* Using TypeScript:
|
|
22
24
|
* - this function require each locale to be defined if defined in the project configuration.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
2
2
|
import { NodeType } from '../../../types/index.mjs';
|
|
3
3
|
import { getStackTraceInfo } from '../../../utils/getStackTraceInfo.mjs';
|
|
4
|
-
const { defaultLocale } = intlayerConfiguration.internationalization;
|
|
5
4
|
const translation = (content) => {
|
|
5
|
+
const {
|
|
6
|
+
internationalization: { defaultLocale }
|
|
7
|
+
} = getConfiguration();
|
|
6
8
|
const stackTraceInfo = getStackTraceInfo();
|
|
7
9
|
if (typeof content === "string") {
|
|
8
10
|
const result2 = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport { getStackTraceInfo } from '../../../utils/getStackTraceInfo';\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 const stackTraceInfo = getStackTraceInfo();\n\n if (typeof content === 'string') {\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\n [defaultLocale]: content,\n } as TranslationContent<Content>;\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n ...stackTraceInfo,\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;AACzB,SAAS,yBAAyB;AAuBlC,MAAM,cAAc,CAClB,YACG;AACH,QAAM;AAAA,IACJ,sBAAsB,EAAE,cAAc;AAAA,EACxC,IAAI,iBAAiB;AAErB,QAAM,iBAAiB,kBAAkB;AAEzC,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,SAAS;AAAA,MACnB,GAAG;AAAA,MACH,CAAC,aAAa,GAAG;AAAA,IACnB;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,GAAG;AAAA,IACH,GAAI;AAAA,EACN;AAEA,SAAO;AACT;","names":["result"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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": "^1.2.
|
|
54
|
+
"@intlayer/config": "^1.2.1"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^20.12.7",
|
|
@@ -38,12 +38,14 @@ export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
|
38
38
|
*
|
|
39
39
|
* Usage:
|
|
40
40
|
*
|
|
41
|
+
* ```ts
|
|
41
42
|
* const content = enu({
|
|
42
43
|
* '<=-2.3': 'You have less than -2.3',
|
|
43
44
|
* '<1': 'You have less than one',
|
|
44
45
|
* '2': 'You have two',
|
|
45
46
|
* '>=3': 'You have three or more',
|
|
46
47
|
* });
|
|
48
|
+
* ```
|
|
47
49
|
*
|
|
48
50
|
* The order of the keys will define the priority of the content.
|
|
49
51
|
*
|
|
@@ -7,22 +7,25 @@ type Key = keyof QuantityContent<string>;
|
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
*
|
|
10
|
+
* ```ts
|
|
10
11
|
* const content = getEnumerationContent({
|
|
11
12
|
* '<=-2.3': 'You have less than -2.3',
|
|
12
13
|
* '<1': 'You have less than one',
|
|
13
14
|
* '2': 'You have two',
|
|
14
15
|
* '>=3': 'You have three or more',
|
|
15
|
-
* },
|
|
16
|
-
* 2);
|
|
16
|
+
* }, 2);
|
|
17
17
|
* // 'You have two'
|
|
18
|
+
* ```
|
|
18
19
|
*
|
|
19
20
|
* The order of the keys will define the priority of the content.
|
|
20
21
|
*
|
|
22
|
+
* ```ts
|
|
21
23
|
* const content = getEnumerationContent({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* });
|
|
24
|
+
* '<4': 'You have less than four',
|
|
25
|
+
* '2': 'You have two',
|
|
26
|
+
* }, 2);
|
|
25
27
|
* // 'You have less than four'
|
|
28
|
+
* ```
|
|
26
29
|
*
|
|
27
30
|
*/
|
|
28
31
|
export const getEnumerationContent = <Content>(
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type Locales,
|
|
3
|
-
intlayerIntlConfiguration,
|
|
4
|
-
} from '@intlayer/config/client';
|
|
1
|
+
import { type Locales, getConfiguration } from '@intlayer/config/client';
|
|
5
2
|
import type { CustomizableLanguageContent } from './types';
|
|
6
3
|
|
|
7
|
-
const defaultLocale =
|
|
4
|
+
const defaultLocale = getConfiguration().internationalization.defaultLocale;
|
|
8
5
|
|
|
9
6
|
type GetTranslationContent = <Content = string>(
|
|
10
7
|
languageContent: CustomizableLanguageContent<Content>,
|
|
@@ -18,12 +15,13 @@ type GetTranslationContent = <Content = string>(
|
|
|
18
15
|
*
|
|
19
16
|
* Usage:
|
|
20
17
|
*
|
|
18
|
+
* ```ts
|
|
21
19
|
* const content = getTranslationContent({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* },
|
|
25
|
-
* 'fr');
|
|
20
|
+
* en: 'Hello',
|
|
21
|
+
* fr: 'Bonjour',
|
|
22
|
+
* }, 'fr');
|
|
26
23
|
* // 'Bonjour'
|
|
24
|
+
* ```
|
|
27
25
|
*
|
|
28
26
|
* Using TypeScript:
|
|
29
27
|
* - this function will require each locale to be defined if defined in the project configuration.
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfiguration } from '@intlayer/config/client';
|
|
2
2
|
import { NodeType } from '../../../types/index';
|
|
3
3
|
import { getStackTraceInfo } from '../../../utils/getStackTraceInfo';
|
|
4
4
|
import type { CustomizableLanguageContent, TranslationContent } from './types';
|
|
5
5
|
|
|
6
|
-
const { defaultLocale } = intlayerConfiguration.internationalization;
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
*
|
|
10
8
|
* Function intended to be used to build intlayer dictionaries.
|
|
@@ -13,11 +11,13 @@ const { defaultLocale } = intlayerConfiguration.internationalization;
|
|
|
13
11
|
*
|
|
14
12
|
* Usage:
|
|
15
13
|
*
|
|
14
|
+
* ```ts
|
|
16
15
|
* translation<string>({
|
|
17
16
|
* "en": "Hello",
|
|
18
17
|
* "fr": "Bonjour",
|
|
19
18
|
* // ... any other available locale
|
|
20
19
|
* })
|
|
20
|
+
* ```
|
|
21
21
|
*
|
|
22
22
|
* Using TypeScript:
|
|
23
23
|
* - this function require each locale to be defined if defined in the project configuration.
|
|
@@ -26,6 +26,10 @@ const { defaultLocale } = intlayerConfiguration.internationalization;
|
|
|
26
26
|
const translation = <Content = string>(
|
|
27
27
|
content?: CustomizableLanguageContent<Content>
|
|
28
28
|
) => {
|
|
29
|
+
const {
|
|
30
|
+
internationalization: { defaultLocale },
|
|
31
|
+
} = getConfiguration();
|
|
32
|
+
|
|
29
33
|
const stackTraceInfo = getStackTraceInfo();
|
|
30
34
|
|
|
31
35
|
if (typeof content === 'string') {
|