@intlayer/core 1.0.1 → 1.2.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/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +15 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +23 -0
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +18 -0
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +10 -13
- package/dist/cjs/utils/getStackTraceInfo.cjs.map +1 -1
- package/dist/cjs/utils/getStackTraceInfo.d.ts +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +15 -1
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +23 -0
- package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +18 -0
- package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +10 -13
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -1
- package/dist/esm/utils/getStackTraceInfo.d.mts +1 -1
- package/dist/esm/utils/getStackTraceInfo.mjs.map +1 -1
- package/package.json +6 -5
- package/src/transpiler/content_transformers/enumeration/enumeration.ts +15 -1
- package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +23 -0
- package/src/transpiler/content_transformers/translation/getTranslationContent.ts +18 -0
- package/src/transpiler/content_transformers/translation/translation.ts +10 -13
- package/src/utils/getStackTraceInfo.ts +1 -1
|
@@ -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 *
|
|
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;AA6CP,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"]}
|
|
@@ -16,7 +16,21 @@ type EnumerationContent<Content> = Partial<QuantityContent<Content>> & NoteStack
|
|
|
16
16
|
nodeType: NodeType.Enumeration;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
20
|
+
*
|
|
21
|
+
* Allow to pick a content based on a quantity.
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
*
|
|
25
|
+
* const content = enu({
|
|
26
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
27
|
+
* '<1': 'You have less than one',
|
|
28
|
+
* '2': 'You have two',
|
|
29
|
+
* '>=3': 'You have three or more',
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* The order of the keys will define the priority of the content.
|
|
33
|
+
*
|
|
20
34
|
*/
|
|
21
35
|
declare const enumeration: <Content>(content?: Partial<QuantityContent<Content>>) => EnumerationContent<Content>;
|
|
22
36
|
|
|
@@ -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\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;
|
|
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 * },\n * 2);\n * // 'You have two'\n *\n * The order of the keys will define the priority of the content.\n *\n * const content = getEnumerationContent({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * });\n * // 'You have less than four'\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;AA2BO,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":[]}
|
|
@@ -2,6 +2,29 @@ import { QuantityContent } from './enumeration.js';
|
|
|
2
2
|
import '../../../utils/getStackTraceInfo.js';
|
|
3
3
|
import '../../../types/nodeType.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Allow to pick a content based on a quantity.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* const content = getEnumerationContent({
|
|
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
|
+
* },
|
|
16
|
+
* 2);
|
|
17
|
+
* // 'You have two'
|
|
18
|
+
*
|
|
19
|
+
* The order of the keys will define the priority of the content.
|
|
20
|
+
*
|
|
21
|
+
* const content = getEnumerationContent({
|
|
22
|
+
* '<4': 'You have less than four',
|
|
23
|
+
* '2': 'You have two',
|
|
24
|
+
* });
|
|
25
|
+
* // 'You have less than four'
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
5
28
|
declare const getEnumerationContent: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
6
29
|
|
|
7
30
|
export { getEnumerationContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport type { CustomizableLanguageContent } from './types';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\ntype GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => Content;\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,oBAGO;AAGP,MAAM,gBAAgB,wCAA0B;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport type { CustomizableLanguageContent } from './types';\n\nconst defaultLocale = intlayerIntlConfiguration.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 * const content = getTranslationContent({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\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,oBAGO;AAGP,MAAM,gBAAgB,wCAA0B;AAyBzC,MAAM,wBAA+C,CAC1D,iBACA,WACG,gBAAgB,UAAU,aAAa,KAAK,gBAAgB,aAAa;","names":[]}
|
|
@@ -5,6 +5,24 @@ import '../../../utils/getStackTraceInfo.js';
|
|
|
5
5
|
import '../../../types/nodeType.js';
|
|
6
6
|
|
|
7
7
|
type GetTranslationContent = <Content = string>(languageContent: CustomizableLanguageContent<Content>, locale: Locales) => Content;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Allow to pick a content based on a locale.
|
|
11
|
+
* If not locale found, it will return the content related to the default locale.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* const content = getTranslationContent({
|
|
16
|
+
* en: 'Hello',
|
|
17
|
+
* fr: 'Bonjour',
|
|
18
|
+
* },
|
|
19
|
+
* 'fr');
|
|
20
|
+
* // 'Bonjour'
|
|
21
|
+
*
|
|
22
|
+
* Using TypeScript:
|
|
23
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
24
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
25
|
+
*/
|
|
8
26
|
declare const getTranslationContent: GetTranslationContent;
|
|
9
27
|
|
|
10
28
|
export { getTranslationContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { intlayerConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport { getStackTraceInfo } from '../../../utils/getStackTraceInfo';\nimport type { CustomizableLanguageContent, TranslationContent } from './types';\n\nconst { defaultLocale } = intlayerConfiguration.internationalization;\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { intlayerConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport { getStackTraceInfo } from '../../../utils/getStackTraceInfo';\nimport type { CustomizableLanguageContent, TranslationContent } from './types';\n\nconst { defaultLocale } = intlayerConfiguration.internationalization;\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 * translation<string>({\n * \"en\": \"Hello\",\n * \"fr\": \"Bonjour\",\n * // ... any other available locale\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 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,oBAAsC;AACtC,mBAAyB;AACzB,+BAAkC;AAGlC,MAAM,EAAE,cAAc,IAAI,oCAAsB;AAoBhD,MAAM,cAAc,CAClB,YACG;AACH,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"]}
|
|
@@ -5,25 +5,22 @@ import '../../../utils/getStackTraceInfo.js';
|
|
|
5
5
|
import '../../../types/nodeType.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Transpile multilingual dictionary content
|
|
9
8
|
*
|
|
10
|
-
*
|
|
9
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
* "en": "test",
|
|
14
|
-
* "fr": "test",
|
|
15
|
-
* // ... any other available locale
|
|
16
|
-
* })
|
|
11
|
+
* Get the content of a translation based on the locale.
|
|
17
12
|
*
|
|
18
|
-
*
|
|
19
|
-
* "en": 1
|
|
20
|
-
* })
|
|
13
|
+
* Usage:
|
|
21
14
|
*
|
|
22
|
-
* translation<string
|
|
23
|
-
*
|
|
24
|
-
*
|
|
15
|
+
* translation<string>({
|
|
16
|
+
* "en": "Hello",
|
|
17
|
+
* "fr": "Bonjour",
|
|
18
|
+
* // ... any other available locale
|
|
25
19
|
* })
|
|
26
20
|
*
|
|
21
|
+
* Using TypeScript:
|
|
22
|
+
* - this function require each locale to be defined if defined in the project configuration.
|
|
23
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
27
24
|
*/
|
|
28
25
|
declare const translation: <Content = string>(content?: CustomizableLanguageContent<Content>) => TranslationContent<Content>;
|
|
29
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/getStackTraceInfo.ts"],"sourcesContent":["export type NoteStackTraceInfo = {\n file?: string;\n line?: string;\n column?: string;\n};\n\n/**\n * Get the file path, line number, and column number of the caller of this function\n *
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/getStackTraceInfo.ts"],"sourcesContent":["export type NoteStackTraceInfo = {\n file?: string;\n line?: string;\n column?: string;\n};\n\n/**\n * Get the file path, line number, and column number of the caller of this function\n * Return an object containing file, line, and column numbers\n */\nexport const getStackTraceInfo = (): NoteStackTraceInfo => {\n // Create a new Error object to capture the stack trace\n const err = new Error();\n const stack = err.stack ?? '';\n\n // Split the stack trace into lines and find the line where this function was called\n // Adjust the line index as necessary based on how your environment's stack trace format\n const stackLines = stack.split('\\n');\n const callerLine = stackLines[2] ?? ''; // Adjust the index 2 if needed\n\n // Extract file path, line number, and column number using a regular expression\n // This regex pattern might need adjustments based on your environment\n const match = callerLine.match(/at\\s[^(:]+\\([^:]+:(\\d+):(\\d+)\\)?/);\n\n // const file = match?.[1];\n const line = match?.[1];\n const column = match?.[2];\n\n if (match) {\n return {\n // file,\n line,\n column,\n };\n }\n\n // Return empty object if parsing fails\n return {};\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,MAAM,oBAAoB,MAA0B;AAEzD,QAAM,MAAM,IAAI,MAAM;AACtB,QAAM,QAAQ,IAAI,SAAS;AAI3B,QAAM,aAAa,MAAM,MAAM,IAAI;AACnC,QAAM,aAAa,WAAW,CAAC,KAAK;AAIpC,QAAM,QAAQ,WAAW,MAAM,kCAAkC;AAGjE,QAAM,OAAO,QAAQ,CAAC;AACtB,QAAM,SAAS,QAAQ,CAAC;AAExB,MAAI,OAAO;AACT,WAAO;AAAA;AAAA,MAEL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,SAAO,CAAC;AACV;","names":[]}
|
|
@@ -5,7 +5,7 @@ type NoteStackTraceInfo = {
|
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Get the file path, line number, and column number of the caller of this function
|
|
8
|
-
*
|
|
8
|
+
* Return an object containing file, line, and column numbers
|
|
9
9
|
*/
|
|
10
10
|
declare const getStackTraceInfo: () => NoteStackTraceInfo;
|
|
11
11
|
|
|
@@ -16,7 +16,21 @@ type EnumerationContent<Content> = Partial<QuantityContent<Content>> & NoteStack
|
|
|
16
16
|
nodeType: NodeType.Enumeration;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
20
|
+
*
|
|
21
|
+
* Allow to pick a content based on a quantity.
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
*
|
|
25
|
+
* const content = enu({
|
|
26
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
27
|
+
* '<1': 'You have less than one',
|
|
28
|
+
* '2': 'You have two',
|
|
29
|
+
* '>=3': 'You have three or more',
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* The order of the keys will define the priority of the content.
|
|
33
|
+
*
|
|
20
34
|
*/
|
|
21
35
|
declare const enumeration: <Content>(content?: Partial<QuantityContent<Content>>) => EnumerationContent<Content>;
|
|
22
36
|
|
|
@@ -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 *
|
|
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;AA6CP,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"]}
|
|
@@ -2,6 +2,29 @@ import { QuantityContent } from './enumeration.mjs';
|
|
|
2
2
|
import '../../../utils/getStackTraceInfo.mjs';
|
|
3
3
|
import '../../../types/nodeType.mjs';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Allow to pick a content based on a quantity.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* const content = getEnumerationContent({
|
|
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
|
+
* },
|
|
16
|
+
* 2);
|
|
17
|
+
* // 'You have two'
|
|
18
|
+
*
|
|
19
|
+
* The order of the keys will define the priority of the content.
|
|
20
|
+
*
|
|
21
|
+
* const content = getEnumerationContent({
|
|
22
|
+
* '<4': 'You have less than four',
|
|
23
|
+
* '2': 'You have two',
|
|
24
|
+
* });
|
|
25
|
+
* // 'You have less than four'
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
5
28
|
declare const getEnumerationContent: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
6
29
|
|
|
7
30
|
export { getEnumerationContent };
|
|
@@ -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\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":"
|
|
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 * },\n * 2);\n * // 'You have two'\n *\n * The order of the keys will define the priority of the content.\n *\n * const content = getEnumerationContent({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * });\n * // 'You have less than four'\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":"AA2BO,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":[]}
|
|
@@ -5,6 +5,24 @@ import '../../../utils/getStackTraceInfo.mjs';
|
|
|
5
5
|
import '../../../types/nodeType.mjs';
|
|
6
6
|
|
|
7
7
|
type GetTranslationContent = <Content = string>(languageContent: CustomizableLanguageContent<Content>, locale: Locales) => Content;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* Allow to pick a content based on a locale.
|
|
11
|
+
* If not locale found, it will return the content related to the default locale.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
*
|
|
15
|
+
* const content = getTranslationContent({
|
|
16
|
+
* en: 'Hello',
|
|
17
|
+
* fr: 'Bonjour',
|
|
18
|
+
* },
|
|
19
|
+
* 'fr');
|
|
20
|
+
* // 'Bonjour'
|
|
21
|
+
*
|
|
22
|
+
* Using TypeScript:
|
|
23
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
24
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
25
|
+
*/
|
|
8
26
|
declare const getTranslationContent: GetTranslationContent;
|
|
9
27
|
|
|
10
28
|
export { getTranslationContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport type { CustomizableLanguageContent } from './types';\n\nconst defaultLocale = intlayerIntlConfiguration.defaultLocale;\n\ntype GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => Content;\n\nexport const getTranslationContent: GetTranslationContent = <Content = string>(\n languageContent: CustomizableLanguageContent<Content>,\n locale: Locales\n) => languageContent[locale ?? defaultLocale] ?? languageContent[defaultLocale];\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,OACK;AAGP,MAAM,gBAAgB,0BAA0B;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/getTranslationContent.ts"],"sourcesContent":["import {\n type Locales,\n intlayerIntlConfiguration,\n} from '@intlayer/config/client';\nimport type { CustomizableLanguageContent } from './types';\n\nconst defaultLocale = intlayerIntlConfiguration.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 * const content = getTranslationContent({\n * en: 'Hello',\n * fr: 'Bonjour',\n * },\n * 'fr');\n * // 'Bonjour'\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,EAEE;AAAA,OACK;AAGP,MAAM,gBAAgB,0BAA0B;AAyBzC,MAAM,wBAA+C,CAC1D,iBACA,WACG,gBAAgB,UAAU,aAAa,KAAK,gBAAgB,aAAa;","names":[]}
|
|
@@ -5,25 +5,22 @@ import '../../../utils/getStackTraceInfo.mjs';
|
|
|
5
5
|
import '../../../types/nodeType.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Transpile multilingual dictionary content
|
|
9
8
|
*
|
|
10
|
-
*
|
|
9
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
* "en": "test",
|
|
14
|
-
* "fr": "test",
|
|
15
|
-
* // ... any other available locale
|
|
16
|
-
* })
|
|
11
|
+
* Get the content of a translation based on the locale.
|
|
17
12
|
*
|
|
18
|
-
*
|
|
19
|
-
* "en": 1
|
|
20
|
-
* })
|
|
13
|
+
* Usage:
|
|
21
14
|
*
|
|
22
|
-
* translation<string
|
|
23
|
-
*
|
|
24
|
-
*
|
|
15
|
+
* translation<string>({
|
|
16
|
+
* "en": "Hello",
|
|
17
|
+
* "fr": "Bonjour",
|
|
18
|
+
* // ... any other available locale
|
|
25
19
|
* })
|
|
26
20
|
*
|
|
21
|
+
* Using TypeScript:
|
|
22
|
+
* - this function require each locale to be defined if defined in the project configuration.
|
|
23
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
27
24
|
*/
|
|
28
25
|
declare const translation: <Content = string>(content?: CustomizableLanguageContent<Content>) => TranslationContent<Content>;
|
|
29
26
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { intlayerConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport { getStackTraceInfo } from '../../../utils/getStackTraceInfo';\nimport type { CustomizableLanguageContent, TranslationContent } from './types';\n\nconst { defaultLocale } = intlayerConfiguration.internationalization;\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { intlayerConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport { getStackTraceInfo } from '../../../utils/getStackTraceInfo';\nimport type { CustomizableLanguageContent, TranslationContent } from './types';\n\nconst { defaultLocale } = intlayerConfiguration.internationalization;\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 * translation<string>({\n * \"en\": \"Hello\",\n * \"fr\": \"Bonjour\",\n * // ... any other available locale\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 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,6BAA6B;AACtC,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAGlC,MAAM,EAAE,cAAc,IAAI,sBAAsB;AAoBhD,MAAM,cAAc,CAClB,YACG;AACH,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"]}
|
|
@@ -5,7 +5,7 @@ type NoteStackTraceInfo = {
|
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* Get the file path, line number, and column number of the caller of this function
|
|
8
|
-
*
|
|
8
|
+
* Return an object containing file, line, and column numbers
|
|
9
9
|
*/
|
|
10
10
|
declare const getStackTraceInfo: () => NoteStackTraceInfo;
|
|
11
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/getStackTraceInfo.ts"],"sourcesContent":["export type NoteStackTraceInfo = {\n file?: string;\n line?: string;\n column?: string;\n};\n\n/**\n * Get the file path, line number, and column number of the caller of this function\n *
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/getStackTraceInfo.ts"],"sourcesContent":["export type NoteStackTraceInfo = {\n file?: string;\n line?: string;\n column?: string;\n};\n\n/**\n * Get the file path, line number, and column number of the caller of this function\n * Return an object containing file, line, and column numbers\n */\nexport const getStackTraceInfo = (): NoteStackTraceInfo => {\n // Create a new Error object to capture the stack trace\n const err = new Error();\n const stack = err.stack ?? '';\n\n // Split the stack trace into lines and find the line where this function was called\n // Adjust the line index as necessary based on how your environment's stack trace format\n const stackLines = stack.split('\\n');\n const callerLine = stackLines[2] ?? ''; // Adjust the index 2 if needed\n\n // Extract file path, line number, and column number using a regular expression\n // This regex pattern might need adjustments based on your environment\n const match = callerLine.match(/at\\s[^(:]+\\([^:]+:(\\d+):(\\d+)\\)?/);\n\n // const file = match?.[1];\n const line = match?.[1];\n const column = match?.[2];\n\n if (match) {\n return {\n // file,\n line,\n column,\n };\n }\n\n // Return empty object if parsing fails\n return {};\n};\n"],"mappings":"AAUO,MAAM,oBAAoB,MAA0B;AAEzD,QAAM,MAAM,IAAI,MAAM;AACtB,QAAM,QAAQ,IAAI,SAAS;AAI3B,QAAM,aAAa,MAAM,MAAM,IAAI;AACnC,QAAM,aAAa,WAAW,CAAC,KAAK;AAIpC,QAAM,QAAQ,WAAW,MAAM,kCAAkC;AAGjE,QAAM,OAAO,QAAQ,CAAC;AACtB,QAAM,SAAS,QAAQ,CAAC;AAExB,MAAI,OAAO;AACT,WAAO;AAAA;AAAA,MAEL;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,SAAO,CAAC;AACV;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.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": [
|
|
@@ -50,15 +50,16 @@
|
|
|
50
50
|
"./package.json"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"
|
|
53
|
+
"chokidar": "^3.6.0",
|
|
54
|
+
"@intlayer/config": "^1.2.0"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^20.
|
|
57
|
-
"@types/react": "^18.2.
|
|
57
|
+
"@types/node": "^20.12.7",
|
|
58
|
+
"@types/react": "^18.2.79",
|
|
58
59
|
"react": "^18.2.0",
|
|
59
60
|
"rimraf": "5.0.5",
|
|
60
61
|
"tsup": "^8.0.2",
|
|
61
|
-
"typescript": "^5.4.
|
|
62
|
+
"typescript": "^5.4.5",
|
|
62
63
|
"@utils/eslint-config": "^1.0.1",
|
|
63
64
|
"@utils/ts-config": "^1.0.1"
|
|
64
65
|
},
|
|
@@ -32,7 +32,21 @@ export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
36
|
+
*
|
|
37
|
+
* Allow to pick a content based on a quantity.
|
|
38
|
+
*
|
|
39
|
+
* Usage:
|
|
40
|
+
*
|
|
41
|
+
* const content = enu({
|
|
42
|
+
* '<=-2.3': 'You have less than -2.3',
|
|
43
|
+
* '<1': 'You have less than one',
|
|
44
|
+
* '2': 'You have two',
|
|
45
|
+
* '>=3': 'You have three or more',
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* The order of the keys will define the priority of the content.
|
|
49
|
+
*
|
|
36
50
|
*/
|
|
37
51
|
const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
|
|
38
52
|
const stackTraceInfo = getStackTraceInfo();
|
|
@@ -2,6 +2,29 @@ import type { QuantityContent } from './enumeration';
|
|
|
2
2
|
|
|
3
3
|
type Key = keyof QuantityContent<string>;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Allow to pick a content based on a quantity.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* const content = getEnumerationContent({
|
|
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
|
+
* },
|
|
16
|
+
* 2);
|
|
17
|
+
* // 'You have two'
|
|
18
|
+
*
|
|
19
|
+
* The order of the keys will define the priority of the content.
|
|
20
|
+
*
|
|
21
|
+
* const content = getEnumerationContent({
|
|
22
|
+
* '<4': 'You have less than four',
|
|
23
|
+
* '2': 'You have two',
|
|
24
|
+
* });
|
|
25
|
+
* // 'You have less than four'
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
5
28
|
export const getEnumerationContent = <Content>(
|
|
6
29
|
enumerationContent: QuantityContent<Content>,
|
|
7
30
|
quantity: number
|
|
@@ -11,6 +11,24 @@ type GetTranslationContent = <Content = string>(
|
|
|
11
11
|
locale: Locales
|
|
12
12
|
) => Content;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* Allow to pick a content based on a locale.
|
|
17
|
+
* If not locale found, it will return the content related to the default locale.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
*
|
|
21
|
+
* const content = getTranslationContent({
|
|
22
|
+
* en: 'Hello',
|
|
23
|
+
* fr: 'Bonjour',
|
|
24
|
+
* },
|
|
25
|
+
* 'fr');
|
|
26
|
+
* // 'Bonjour'
|
|
27
|
+
*
|
|
28
|
+
* Using TypeScript:
|
|
29
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
30
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
31
|
+
*/
|
|
14
32
|
export const getTranslationContent: GetTranslationContent = <Content = string>(
|
|
15
33
|
languageContent: CustomizableLanguageContent<Content>,
|
|
16
34
|
locale: Locales
|
|
@@ -6,25 +6,22 @@ import type { CustomizableLanguageContent, TranslationContent } from './types';
|
|
|
6
6
|
const { defaultLocale } = intlayerConfiguration.internationalization;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Transpile multilingual dictionary content
|
|
10
9
|
*
|
|
11
|
-
*
|
|
10
|
+
* Function intended to be used to build intlayer dictionaries.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
* "en": "test",
|
|
15
|
-
* "fr": "test",
|
|
16
|
-
* // ... any other available locale
|
|
17
|
-
* })
|
|
12
|
+
* Get the content of a translation based on the locale.
|
|
18
13
|
*
|
|
19
|
-
*
|
|
20
|
-
* "en": 1
|
|
21
|
-
* })
|
|
14
|
+
* Usage:
|
|
22
15
|
*
|
|
23
|
-
* translation<string
|
|
24
|
-
*
|
|
25
|
-
*
|
|
16
|
+
* translation<string>({
|
|
17
|
+
* "en": "Hello",
|
|
18
|
+
* "fr": "Bonjour",
|
|
19
|
+
* // ... any other available locale
|
|
26
20
|
* })
|
|
27
21
|
*
|
|
22
|
+
* Using TypeScript:
|
|
23
|
+
* - this function require each locale to be defined if defined in the project configuration.
|
|
24
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
28
25
|
*/
|
|
29
26
|
const translation = <Content = string>(
|
|
30
27
|
content?: CustomizableLanguageContent<Content>
|
|
@@ -6,7 +6,7 @@ export type NoteStackTraceInfo = {
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Get the file path, line number, and column number of the caller of this function
|
|
9
|
-
*
|
|
9
|
+
* Return an object containing file, line, and column numbers
|
|
10
10
|
*/
|
|
11
11
|
export const getStackTraceInfo = (): NoteStackTraceInfo => {
|
|
12
12
|
// Create a new Error object to capture the stack trace
|