@intlayer/core 1.2.0 → 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 +4 -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 +8 -6
- 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.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 +6 -5
- package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +2 -2
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs +3 -5
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +5 -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 +4 -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 +8 -6
- 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 +6 -5
- 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/index.d.mts +2 -2
- package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +5 -3
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs +4 -6
- 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 +6 -13
- package/src/transpiler/content_transformers/enumeration/findMatchingCondition.ts +64 -0
- package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +11 -36
- package/src/transpiler/content_transformers/enumeration/index.ts +1 -0
- package/src/transpiler/content_transformers/translation/getTranslationContent.ts +7 -9
- package/src/transpiler/content_transformers/translation/translation.ts +6 -7
- 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
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type {\n CustomizableLanguageContent,\n LanguageContent,\n TranslationContent,\n EnumerationContent,\n QuantityContent,\n CustomLocales as Locales,\n} from './transpiler/content_transformers/index';\nexport {\n t,\n enu,\n getTranslationContent,\n getEnumerationContent,\n} from './transpiler/content_transformers/index';\nexport type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n ContentModule,\n} from './types/index';\nexport { NodeType } from './types/index';\nexport { getLocaleName } from './getLocaleName';\nexport { localeList } from './localeList';\n"],"mappings":"AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type {\n CustomizableLanguageContent,\n LanguageContent,\n TranslationContent,\n EnumerationContent,\n QuantityContent,\n CustomLocales as Locales,\n} from './transpiler/content_transformers/index';\nexport {\n t,\n enu,\n getTranslationContent,\n findMatchingCondition,\n getEnumerationContent,\n} from './transpiler/content_transformers/index';\nexport type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n ContentModule,\n KeyPath,\n ObjectExpressionNode,\n TranslationOrEnumerationNode,\n} from './types/index';\nexport { NodeType } from './types/index';\nexport { getLocaleName } from './getLocaleName';\nexport { localeList } from './localeList';\n"],"mappings":"AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;","names":[]}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo.mjs';
|
|
2
1
|
import { NodeType } from '../../../types/nodeType.mjs';
|
|
3
2
|
|
|
4
3
|
type Positif = number | `${number}`;
|
|
@@ -12,7 +11,7 @@ type Inferior = `<${Numbers}`;
|
|
|
12
11
|
type InferiorOrEqual = `<=${Numbers}`;
|
|
13
12
|
type EnterFormat = Equal | EqualString | Superior | SuperiorOrEqual | Inferior | InferiorOrEqual;
|
|
14
13
|
type QuantityContent<Content> = Record<EnterFormat, Content>;
|
|
15
|
-
type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
14
|
+
type EnumerationContent<Content> = Partial<QuantityContent<Content>> & {
|
|
16
15
|
nodeType: NodeType.Enumeration;
|
|
17
16
|
};
|
|
18
17
|
/**
|
|
@@ -22,16 +21,18 @@ type EnumerationContent<Content> = Partial<QuantityContent<Content>> & NoteStack
|
|
|
22
21
|
*
|
|
23
22
|
* Usage:
|
|
24
23
|
*
|
|
24
|
+
* ```ts
|
|
25
25
|
* const content = enu({
|
|
26
26
|
* '<=-2.3': 'You have less than -2.3',
|
|
27
27
|
* '<1': 'You have less than one',
|
|
28
28
|
* '2': 'You have two',
|
|
29
29
|
* '>=3': 'You have three or more',
|
|
30
30
|
* });
|
|
31
|
+
* ```
|
|
31
32
|
*
|
|
32
33
|
* The order of the keys will define the priority of the content.
|
|
33
34
|
*
|
|
34
35
|
*/
|
|
35
36
|
declare const enumeration: <Content>(content?: Partial<QuantityContent<Content>>) => EnumerationContent<Content>;
|
|
36
37
|
|
|
37
|
-
export { type EnumerationContent, type QuantityContent, enumeration as enu };
|
|
38
|
+
export { type EnterFormat, type EnumerationContent, type QuantityContent, enumeration as enu };
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { NodeType } from '../../../types/index.mjs';
|
|
2
|
-
import {
|
|
3
|
-
getStackTraceInfo
|
|
4
|
-
} from '../../../utils/getStackTraceInfo.mjs';
|
|
5
2
|
const enumeration = (content) => {
|
|
6
|
-
const stackTraceInfo = getStackTraceInfo();
|
|
7
3
|
if (typeof content === "string") {
|
|
8
4
|
const result2 = {
|
|
9
5
|
nodeType: NodeType.Enumeration,
|
|
10
|
-
...stackTraceInfo,
|
|
11
6
|
1: content
|
|
12
7
|
};
|
|
13
8
|
return result2;
|
|
14
9
|
}
|
|
15
10
|
const result = {
|
|
16
11
|
nodeType: NodeType.Enumeration,
|
|
17
|
-
...stackTraceInfo,
|
|
18
12
|
...content
|
|
19
13
|
};
|
|
20
14
|
return result;
|
|
@@ -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';\
|
|
1
|
+
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/enumeration.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { NodeType } from '../../../types/index';\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\nexport type 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 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 if (typeof content === 'string') {\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n 1: content,\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n ...content,\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":"AACA,SAAS,gBAAgB;AA8CzB,MAAM,cAAc,CAAU,YAAgD;AAC5E,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,SAAS;AAAA,MACnB,GAAG;AAAA,IACL;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,GAAG;AAAA,EACL;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -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,5 +1,4 @@
|
|
|
1
1
|
import { QuantityContent } from './enumeration.mjs';
|
|
2
|
-
import '../../../utils/getStackTraceInfo.mjs';
|
|
3
2
|
import '../../../types/nodeType.mjs';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -7,22 +6,25 @@ import '../../../types/nodeType.mjs';
|
|
|
7
6
|
*
|
|
8
7
|
* Usage:
|
|
9
8
|
*
|
|
9
|
+
* ```ts
|
|
10
10
|
* const content = getEnumerationContent({
|
|
11
11
|
* '<=-2.3': 'You have less than -2.3',
|
|
12
12
|
* '<1': 'You have less than one',
|
|
13
13
|
* '2': 'You have two',
|
|
14
14
|
* '>=3': 'You have three or more',
|
|
15
|
-
* },
|
|
16
|
-
* 2);
|
|
15
|
+
* }, 2);
|
|
17
16
|
* // 'You have two'
|
|
17
|
+
* ```
|
|
18
18
|
*
|
|
19
19
|
* The order of the keys will define the priority of the content.
|
|
20
20
|
*
|
|
21
|
+
* ```ts
|
|
21
22
|
* const content = getEnumerationContent({
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* });
|
|
23
|
+
* '<4': 'You have less than four',
|
|
24
|
+
* '2': 'You have two',
|
|
25
|
+
* }, 2);
|
|
25
26
|
* // 'You have less than four'
|
|
27
|
+
* ```
|
|
26
28
|
*
|
|
27
29
|
*/
|
|
28
30
|
declare const getEnumerationContent: <Content>(enumerationContent: QuantityContent<Content>, quantity: number) => Content;
|
|
@@ -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
|
/**
|
|
@@ -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":[]}
|
|
@@ -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
|
*
|
|
@@ -12,16 +12,18 @@ 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.
|
|
23
25
|
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
24
26
|
*/
|
|
25
|
-
declare const translation: <Content = string>(content?:
|
|
27
|
+
declare const translation: <Content = string>(content?: any) => TranslationContent<Content>;
|
|
26
28
|
|
|
27
29
|
export { translation as t };
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getConfiguration } from "@intlayer/config/client";
|
|
2
2
|
import { NodeType } from '../../../types/index.mjs';
|
|
3
|
-
import { getStackTraceInfo } from '../../../utils/getStackTraceInfo.mjs';
|
|
4
|
-
const { defaultLocale } = intlayerConfiguration.internationalization;
|
|
5
3
|
const translation = (content) => {
|
|
6
|
-
const
|
|
4
|
+
const {
|
|
5
|
+
internationalization: { defaultLocale }
|
|
6
|
+
} = getConfiguration();
|
|
7
7
|
if (typeof content === "string") {
|
|
8
8
|
const result2 = {
|
|
9
9
|
nodeType: NodeType.Translation,
|
|
10
|
-
...stackTraceInfo,
|
|
11
10
|
[defaultLocale]: content
|
|
12
11
|
};
|
|
13
12
|
return result2;
|
|
14
13
|
}
|
|
15
14
|
const result = {
|
|
16
15
|
nodeType: NodeType.Translation,
|
|
17
|
-
...stackTraceInfo,
|
|
18
16
|
...content
|
|
19
17
|
};
|
|
20
18
|
return result;
|
|
@@ -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 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.
|
|
@@ -38,23 +33,22 @@ export type EnumerationContent<Content> = Partial<QuantityContent<Content>> &
|
|
|
38
33
|
*
|
|
39
34
|
* Usage:
|
|
40
35
|
*
|
|
36
|
+
* ```ts
|
|
41
37
|
* const content = enu({
|
|
42
38
|
* '<=-2.3': 'You have less than -2.3',
|
|
43
39
|
* '<1': 'You have less than one',
|
|
44
40
|
* '2': 'You have two',
|
|
45
41
|
* '>=3': 'You have three or more',
|
|
46
42
|
* });
|
|
43
|
+
* ```
|
|
47
44
|
*
|
|
48
45
|
* The order of the keys will define the priority of the content.
|
|
49
46
|
*
|
|
50
47
|
*/
|
|
51
48
|
const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
|
|
52
|
-
const stackTraceInfo = getStackTraceInfo();
|
|
53
|
-
|
|
54
49
|
if (typeof content === 'string') {
|
|
55
50
|
const result: EnumerationContent<Content> = {
|
|
56
51
|
nodeType: NodeType.Enumeration,
|
|
57
|
-
...stackTraceInfo,
|
|
58
52
|
1: content,
|
|
59
53
|
};
|
|
60
54
|
|
|
@@ -63,7 +57,6 @@ const enumeration = <Content>(content?: Partial<QuantityContent<Content>>) => {
|
|
|
63
57
|
|
|
64
58
|
const result: EnumerationContent<Content> = {
|
|
65
59
|
nodeType: NodeType.Enumeration,
|
|
66
|
-
...stackTraceInfo,
|
|
67
60
|
...content,
|
|
68
61
|
};
|
|
69
62
|
|