@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.
Files changed (76) hide show
  1. package/dist/cjs/index.cjs +2 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.ts +2 -0
  4. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs +0 -4
  5. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
  6. package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +4 -3
  7. package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.cjs +42 -0
  8. package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.cjs.map +1 -0
  9. package/dist/cjs/transpiler/content_transformers/enumeration/findMatchingCondition.d.ts +33 -0
  10. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs +3 -12
  11. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.cjs.map +1 -1
  12. package/dist/cjs/transpiler/content_transformers/enumeration/getEnumerationContent.d.ts +8 -6
  13. package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs +3 -1
  14. package/dist/cjs/transpiler/content_transformers/enumeration/index.cjs.map +1 -1
  15. package/dist/cjs/transpiler/content_transformers/enumeration/index.d.ts +2 -2
  16. package/dist/cjs/transpiler/content_transformers/index.d.ts +4 -3
  17. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs +1 -1
  18. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.cjs.map +1 -1
  19. package/dist/cjs/transpiler/content_transformers/translation/getTranslationContent.d.ts +6 -5
  20. package/dist/cjs/transpiler/content_transformers/translation/index.d.ts +2 -2
  21. package/dist/cjs/transpiler/content_transformers/translation/translation.cjs +3 -5
  22. package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
  23. package/dist/cjs/transpiler/content_transformers/translation/translation.d.ts +5 -3
  24. package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -1
  25. package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +3 -4
  26. package/dist/cjs/transpiler/index.d.ts +4 -3
  27. package/dist/cjs/types/contentModule.cjs.map +1 -1
  28. package/dist/cjs/types/contentModule.d.ts +2 -1
  29. package/dist/cjs/types/index.cjs.map +1 -1
  30. package/dist/cjs/types/index.d.ts +1 -0
  31. package/dist/cjs/types/keyPath.cjs +17 -0
  32. package/dist/cjs/types/keyPath.cjs.map +1 -0
  33. package/dist/cjs/types/keyPath.d.ts +13 -0
  34. package/dist/esm/index.d.mts +2 -0
  35. package/dist/esm/index.mjs +2 -0
  36. package/dist/esm/index.mjs.map +1 -1
  37. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +4 -3
  38. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs +0 -6
  39. package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
  40. package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.d.mts +33 -0
  41. package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.mjs +18 -0
  42. package/dist/esm/transpiler/content_transformers/enumeration/findMatchingCondition.mjs.map +1 -0
  43. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.d.mts +8 -6
  44. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs +3 -12
  45. package/dist/esm/transpiler/content_transformers/enumeration/getEnumerationContent.mjs.map +1 -1
  46. package/dist/esm/transpiler/content_transformers/enumeration/index.d.mts +2 -2
  47. package/dist/esm/transpiler/content_transformers/enumeration/index.mjs +1 -0
  48. package/dist/esm/transpiler/content_transformers/enumeration/index.mjs.map +1 -1
  49. package/dist/esm/transpiler/content_transformers/index.d.mts +4 -3
  50. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.d.mts +6 -5
  51. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs +2 -4
  52. package/dist/esm/transpiler/content_transformers/translation/getTranslationContent.mjs.map +1 -1
  53. package/dist/esm/transpiler/content_transformers/translation/index.d.mts +2 -2
  54. package/dist/esm/transpiler/content_transformers/translation/translation.d.mts +5 -3
  55. package/dist/esm/transpiler/content_transformers/translation/translation.mjs +4 -6
  56. package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -1
  57. package/dist/esm/transpiler/content_transformers/translation/types.d.mts +3 -4
  58. package/dist/esm/transpiler/index.d.mts +4 -3
  59. package/dist/esm/types/contentModule.d.mts +2 -1
  60. package/dist/esm/types/index.d.mts +1 -0
  61. package/dist/esm/types/index.mjs.map +1 -1
  62. package/dist/esm/types/keyPath.d.mts +13 -0
  63. package/dist/esm/types/keyPath.mjs +1 -0
  64. package/dist/esm/types/keyPath.mjs.map +1 -0
  65. package/package.json +2 -3
  66. package/src/index.ts +4 -0
  67. package/src/transpiler/content_transformers/enumeration/enumeration.ts +6 -13
  68. package/src/transpiler/content_transformers/enumeration/findMatchingCondition.ts +64 -0
  69. package/src/transpiler/content_transformers/enumeration/getEnumerationContent.ts +11 -36
  70. package/src/transpiler/content_transformers/enumeration/index.ts +1 -0
  71. package/src/transpiler/content_transformers/translation/getTranslationContent.ts +7 -9
  72. package/src/transpiler/content_transformers/translation/translation.ts +6 -7
  73. package/src/transpiler/content_transformers/translation/types.ts +1 -2
  74. package/src/types/contentModule.ts +1 -0
  75. package/src/types/index.ts +5 -0
  76. package/src/types/keyPath.ts +13 -0
@@ -20,6 +20,7 @@ var src_exports = {};
20
20
  __export(src_exports, {
21
21
  NodeType: () => import_types.NodeType,
22
22
  enu: () => import_content_transformers.enu,
23
+ findMatchingCondition: () => import_content_transformers.findMatchingCondition,
23
24
  getEnumerationContent: () => import_content_transformers.getEnumerationContent,
24
25
  getLocaleName: () => import_getLocaleName.getLocaleName,
25
26
  getTranslationContent: () => import_content_transformers.getTranslationContent,
@@ -35,6 +36,7 @@ var import_localeList = require('./localeList.cjs');
35
36
  0 && (module.exports = {
36
37
  NodeType,
37
38
  enu,
39
+ findMatchingCondition,
38
40
  getEnumerationContent,
39
41
  getLocaleName,
40
42
  getTranslationContent,
@@ -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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,kCAKO;AASP,mBAAyB;AACzB,2BAA8B;AAC9B,wBAA2B;","names":[]}
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,kCAMO;AAYP,mBAAyB;AACzB,2BAA8B;AAC9B,wBAA2B;","names":[]}
@@ -3,8 +3,10 @@ export { getTranslationContent } from './transpiler/content_transformers/transla
3
3
  export { CustomizableLanguageContent, LanguageContent, CustomLocales as Locales, TranslationContent } from './transpiler/content_transformers/translation/types.js';
4
4
  export { EnumerationContent, QuantityContent, enu } from './transpiler/content_transformers/enumeration/enumeration.js';
5
5
  export { getEnumerationContent } from './transpiler/content_transformers/enumeration/getEnumerationContent.js';
6
+ export { findMatchingCondition } from './transpiler/content_transformers/enumeration/findMatchingCondition.js';
6
7
  export { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode } from './types/contentModule.js';
7
8
  export { NodeType } from './types/nodeType.js';
9
+ export { KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './types/keyPath.js';
8
10
  export { getLocaleName } from './getLocaleName.js';
9
11
  export { localeList } from './localeList.js';
10
12
  import '@intlayer/config/client';
@@ -22,20 +22,16 @@ __export(enumeration_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(enumeration_exports);
24
24
  var import_types = require('../../../types/index.cjs');
25
- var import_getStackTraceInfo = require('../../../utils/getStackTraceInfo.cjs');
26
25
  const enumeration = (content) => {
27
- const stackTraceInfo = (0, import_getStackTraceInfo.getStackTraceInfo)();
28
26
  if (typeof content === "string") {
29
27
  const result2 = {
30
28
  nodeType: import_types.NodeType.Enumeration,
31
- ...stackTraceInfo,
32
29
  1: content
33
30
  };
34
31
  return result2;
35
32
  }
36
33
  const result = {
37
34
  nodeType: import_types.NodeType.Enumeration,
38
- ...stackTraceInfo,
39
35
  ...content
40
36
  };
41
37
  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';\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"]}
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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyB;AA8CzB,MAAM,cAAc,CAAU,YAAgD;AAC5E,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,sBAAS;AAAA,MACnB,GAAG;AAAA,IACL;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,GAAG;AAAA,EACL;AAEA,SAAO;AACT;","names":["result"]}
@@ -1,4 +1,3 @@
1
- import { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo.js';
2
1
  import { NodeType } from '../../../types/nodeType.js';
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>> & NoteStackTraceInfo & {
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 };
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var findMatchingCondition_exports = {};
20
+ __export(findMatchingCondition_exports, {
21
+ findMatchingCondition: () => findMatchingCondition
22
+ });
23
+ module.exports = __toCommonJS(findMatchingCondition_exports);
24
+ const findMatchingCondition = (enumerationContent, quantity) => {
25
+ const numericKeys = Object.keys(enumerationContent);
26
+ for (const key of numericKeys) {
27
+ const isEqual = !key.startsWith(">") && !key.startsWith("<") && !key.startsWith("=") && parseFloat(key) === quantity || key.startsWith("=") && parseFloat(key.slice(1)) === quantity;
28
+ const isSuperior = key.startsWith(">") && quantity > parseFloat(key.slice(1));
29
+ const isSuperiorOrEqual = key.startsWith(">=") && quantity >= parseFloat(key.slice(2));
30
+ const isInferior = key.startsWith("<") && quantity < parseFloat(key.slice(1));
31
+ const isInferiorOrEqual = key.startsWith("<=") && quantity <= parseFloat(key.slice(2));
32
+ if (isEqual || isSuperior || isSuperiorOrEqual || isInferior || isInferiorOrEqual) {
33
+ return key;
34
+ }
35
+ }
36
+ return "1";
37
+ };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ findMatchingCondition
41
+ });
42
+ //# sourceMappingURL=findMatchingCondition.cjs.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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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":[]}
@@ -0,0 +1,33 @@
1
+ import { QuantityContent, EnterFormat } from './enumeration.js';
2
+ import '../../../types/nodeType.js';
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 };
@@ -21,19 +21,10 @@ __export(getEnumerationContent_exports, {
21
21
  getEnumerationContent: () => getEnumerationContent
22
22
  });
23
23
  module.exports = __toCommonJS(getEnumerationContent_exports);
24
+ var import__ = require('../../index.cjs');
24
25
  const getEnumerationContent = (enumerationContent, quantity) => {
25
- const numericKeys = Object.keys(enumerationContent);
26
- for (const key of numericKeys) {
27
- const isEqual = !key.startsWith(">") && !key.startsWith("<") && !key.startsWith("=") && parseFloat(key) === quantity || key.startsWith("=") && parseFloat(key.slice(1)) === quantity;
28
- const isSuperior = key.startsWith(">") && quantity > parseFloat(key.slice(1));
29
- const isSuperiorOrEqual = key.startsWith(">=") && quantity >= parseFloat(key.slice(2));
30
- const isInferior = key.startsWith("<") && quantity < parseFloat(key.slice(1));
31
- const isInferiorOrEqual = key.startsWith("<=") && quantity <= parseFloat(key.slice(2));
32
- if (isEqual || isSuperior || isSuperiorOrEqual || isInferior || isInferiorOrEqual) {
33
- return enumerationContent[key];
34
- }
35
- }
36
- return enumerationContent["1"];
26
+ const key = (0, import__.findMatchingCondition)(enumerationContent, quantity);
27
+ return enumerationContent[key];
37
28
  };
38
29
  // Annotate the CommonJS export names for ESM import in node:
39
30
  0 && (module.exports = {
@@ -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 * },\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":[]}
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;AAAA;AAAA;AAAA;AAAA;AAAA,eAAsC;AA6B/B,MAAM,wBAAwB,CACnC,oBACA,aACY;AACZ,QAAM,UAAM,gCAA+B,oBAAoB,QAAQ;AAGvE,SAAO,mBAAmB,GAAG;AAC/B;","names":[]}
@@ -1,5 +1,4 @@
1
1
  import { QuantityContent } from './enumeration.js';
2
- import '../../../utils/getStackTraceInfo.js';
3
2
  import '../../../types/nodeType.js';
4
3
 
5
4
  /**
@@ -7,22 +6,25 @@ import '../../../types/nodeType.js';
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
- * '<4': 'You have less than four',
23
- * '2': 'You have two',
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;
@@ -17,9 +17,11 @@ var enumeration_exports = {};
17
17
  module.exports = __toCommonJS(enumeration_exports);
18
18
  __reExport(enumeration_exports, require('./enumeration.cjs'), module.exports);
19
19
  __reExport(enumeration_exports, require('./getEnumerationContent.cjs'), module.exports);
20
+ __reExport(enumeration_exports, require('./findMatchingCondition.cjs'), module.exports);
20
21
  // Annotate the CommonJS export names for ESM import in node:
21
22
  0 && (module.exports = {
22
23
  ...require('./enumeration.cjs'),
23
- ...require('./getEnumerationContent.cjs')
24
+ ...require('./getEnumerationContent.cjs'),
25
+ ...require('./findMatchingCondition.cjs')
24
26
  });
25
27
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/content_transformers/enumeration/index.ts"],"sourcesContent":["export * from './enumeration';\nexport * from './getEnumerationContent';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,0BAAd;AACA,gCAAc,oCADd;","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;AAAA;AAAA,gCAAc,0BAAd;AACA,gCAAc,oCADd;AAEA,gCAAc,oCAFd;","names":[]}
@@ -1,4 +1,4 @@
1
- export { EnumerationContent, QuantityContent, enu } from './enumeration.js';
1
+ export { EnterFormat, EnumerationContent, QuantityContent, enu } from './enumeration.js';
2
2
  export { getEnumerationContent } from './getEnumerationContent.js';
3
- import '../../../utils/getStackTraceInfo.js';
3
+ export { findMatchingCondition } from './findMatchingCondition.js';
4
4
  import '../../../types/nodeType.js';
@@ -1,9 +1,10 @@
1
1
  export { t } from './translation/translation.js';
2
2
  export { getTranslationContent } from './translation/getTranslationContent.js';
3
- export { ConfigLanguageContent, ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './translation/types.js';
4
- export { EnumerationContent, QuantityContent, enu } from './enumeration/enumeration.js';
3
+ export { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './translation/types.js';
4
+ export { EnterFormat, EnumerationContent, QuantityContent, enu } from './enumeration/enumeration.js';
5
5
  export { getEnumerationContent } from './enumeration/getEnumerationContent.js';
6
+ export { findMatchingCondition } from './enumeration/findMatchingCondition.js';
6
7
  import '@intlayer/config/client';
7
8
  import 'intlayer';
8
- import '../../utils/getStackTraceInfo.js';
9
9
  import '../../types/nodeType.js';
10
+ import '../../utils/getStackTraceInfo.js';
@@ -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.intlayerIntlConfiguration.defaultLocale;
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 {\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":[]}
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":[]}
@@ -1,8 +1,8 @@
1
1
  import { Locales } from '@intlayer/config/client';
2
2
  import { CustomizableLanguageContent } from './types.js';
3
3
  import 'intlayer';
4
- import '../../../utils/getStackTraceInfo.js';
5
4
  import '../../../types/nodeType.js';
5
+ import '../../../utils/getStackTraceInfo.js';
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
- * en: 'Hello',
17
- * fr: 'Bonjour',
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,7 @@
1
1
  export { t } from './translation.js';
2
2
  export { getTranslationContent } from './getTranslationContent.js';
3
- export { ConfigLanguageContent, ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './types.js';
3
+ export { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './types.js';
4
4
  import '@intlayer/config/client';
5
5
  import 'intlayer';
6
- import '../../../utils/getStackTraceInfo.js';
7
6
  import '../../../types/nodeType.js';
7
+ import '../../../utils/getStackTraceInfo.js';
@@ -23,21 +23,19 @@ __export(translation_exports, {
23
23
  module.exports = __toCommonJS(translation_exports);
24
24
  var import_client = require("@intlayer/config/client");
25
25
  var import_types = require('../../../types/index.cjs');
26
- var import_getStackTraceInfo = require('../../../utils/getStackTraceInfo.cjs');
27
- const { defaultLocale } = import_client.intlayerConfiguration.internationalization;
28
26
  const translation = (content) => {
29
- const stackTraceInfo = (0, import_getStackTraceInfo.getStackTraceInfo)();
27
+ const {
28
+ internationalization: { defaultLocale }
29
+ } = (0, import_client.getConfiguration)();
30
30
  if (typeof content === "string") {
31
31
  const result2 = {
32
32
  nodeType: import_types.NodeType.Translation,
33
- ...stackTraceInfo,
34
33
  [defaultLocale]: content
35
34
  };
36
35
  return result2;
37
36
  }
38
37
  const result = {
39
38
  nodeType: import_types.NodeType.Translation,
40
- ...stackTraceInfo,
41
39
  ...content
42
40
  };
43
41
  return result;
@@ -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 *\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"]}
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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AACjC,mBAAyB;AAuBzB,MAAM,cAAc,CAClB,YACG;AACH,QAAM;AAAA,IACJ,sBAAsB,EAAE,cAAc;AAAA,EACxC,QAAI,gCAAiB;AAErB,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,sBAAS;AAAA,MACnB,CAAC,aAAa,GAAG;AAAA,IACnB;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,GAAI;AAAA,EACN;AAEA,SAAO;AACT;","names":["result"]}
@@ -1,8 +1,8 @@
1
- import { CustomizableLanguageContent, TranslationContent } from './types.js';
1
+ import { TranslationContent } from './types.js';
2
2
  import '@intlayer/config/client';
3
3
  import 'intlayer';
4
- import '../../../utils/getStackTraceInfo.js';
5
4
  import '../../../types/nodeType.js';
5
+ import '../../../utils/getStackTraceInfo.js';
6
6
 
7
7
  /**
8
8
  *
@@ -12,16 +12,18 @@ 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.
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?: CustomizableLanguageContent<Content>) => TranslationContent<Content>;
27
+ declare const translation: <Content = string>(content?: any) => TranslationContent<Content>;
26
28
 
27
29
  export { translation as t };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/types.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n// @ts-expect-error intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport type { NodeType } from '../../../types';\nimport type { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return all available locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n */\nexport type CustomLocales = ConfigLocales extends never\n ? LocalesValues\n : ConfigLocales;\n\n/**\n * Record of locales and content\n *\n * const myVar1: LanguageContent<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: LanguageContent<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;\nexport type ConfigLanguageContent<Content> = Record<ConfigLocales, Content>;\n\n/**\n * Valid\n * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {\n * \"en\": \"test\",\n * \"fr\": \"test\"\n * }\n *\n * const test: CustomizableLanguageContent<number> = {\n * \"fr\": 1,\n * \"en\": 1,\n * ... any other available locale\n * }\n *\n * Invalid\n *\n * const test: CustomizableLanguageContent<string> = {\n * \"en\": \"test\",\n * \"fr\": \"test\",\n * \"sss\": \"test\" // Does not exist in Locales\n * }\n *\n * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {\n * \"fr\": \"test\"\n * // Locales.ENGLISH is missing\n * }\n *\n */\nexport type CustomizableLanguageContent<Content = string> =\n ConfigLocales extends never\n ? LanguageContent<Content>\n : ConfigLanguageContent<Content>;\n\nexport type TranslationContent<Content> = LanguageContent<Content> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Translation;\n };\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/types.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n// @ts-expect-error intlayer declared for module augmentation\nimport type { IConfigLocales } from 'intlayer';\nimport type { NodeType } from '../../../types';\nimport type { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo';\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return never\n */\nexport type ConfigLocales = keyof IConfigLocales<unknown>;\n\n/**\n * If module augmented, it will return the configured locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n * If not, it will return all available locales such as Locales.ENGLISH | Locales.FRENCH | Locales.SPANISH | ...\n */\nexport type CustomLocales = ConfigLocales extends never\n ? LocalesValues\n : ConfigLocales;\n\n/**\n * Record of locales and content\n *\n * const myVar1: LanguageContent<string> = {\n * \"en\": \"\",\n * \"fr\": \"\"\n * }\n *\n * const myVar2: LanguageContent<{age: number, name: string}> = {\n * \"en\": {age: 1, name: \"test\"},\n * \"fr\": {age: 1, name: \"test\"}\n * }\n */\nexport type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;\n\n/**\n * Valid\n * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {\n * \"en\": \"test\",\n * \"fr\": \"test\"\n * }\n *\n * const test: CustomizableLanguageContent<number> = {\n * \"fr\": 1,\n * \"en\": 1,\n * ... any other available locale\n * }\n *\n * Invalid\n *\n * const test: CustomizableLanguageContent<string> = {\n * \"en\": \"test\",\n * \"fr\": \"test\",\n * \"sss\": \"test\" // Does not exist in Locales\n * }\n *\n * const test: CustomizableLanguageContent<string, Locales.ENGLISH | Locales.FRENCH> = {\n * \"fr\": \"test\"\n * // Locales.ENGLISH is missing\n * }\n *\n */\nexport type CustomizableLanguageContent<Content = string> =\n ConfigLocales extends never\n ? LanguageContent<Content>\n : IConfigLocales<Content>;\n\nexport type TranslationContent<Content> = LanguageContent<Content> &\n NoteStackTraceInfo & {\n nodeType: NodeType.Translation;\n };\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,7 +1,7 @@
1
1
  import { LocalesValues } from '@intlayer/config/client';
2
2
  import { IConfigLocales } from 'intlayer';
3
- import { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo.js';
4
3
  import { NodeType } from '../../../types/nodeType.js';
4
+ import { NoteStackTraceInfo } from '../../../utils/getStackTraceInfo.js';
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> : ConfigLanguageContent<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 { ConfigLanguageContent, ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent };
62
+ export type { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent };
@@ -1,9 +1,10 @@
1
1
  export { t } from './content_transformers/translation/translation.js';
2
2
  export { getTranslationContent } from './content_transformers/translation/getTranslationContent.js';
3
- export { ConfigLanguageContent, ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './content_transformers/translation/types.js';
4
- export { EnumerationContent, QuantityContent, enu } from './content_transformers/enumeration/enumeration.js';
3
+ export { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent } from './content_transformers/translation/types.js';
4
+ export { EnterFormat, EnumerationContent, QuantityContent, enu } from './content_transformers/enumeration/enumeration.js';
5
5
  export { getEnumerationContent } from './content_transformers/enumeration/getEnumerationContent.js';
6
+ export { findMatchingCondition } from './content_transformers/enumeration/findMatchingCondition.js';
6
7
  import '@intlayer/config/client';
7
8
  import 'intlayer';
8
- import '../utils/getStackTraceInfo.js';
9
9
  import '../types/nodeType.js';
10
+ import '../utils/getStackTraceInfo.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/contentModule.ts"],"sourcesContent":["import type {\n EnumerationContent,\n TranslationContent,\n} from '../transpiler/index';\n\nexport type TypedNode =\n | TranslationContent<unknown>\n | EnumerationContent<unknown>;\n\nexport type ContentValue =\n | string\n | {\n [key: string]: ContentValue;\n }\n | (() => ContentValue)\n | Promise<ContentValue>\n | TypedNode;\n\nexport type Content = Record<string, ContentValue | undefined>;\n\nexport type FlatContentValue =\n | string\n | {\n [key: string]: FlatContentValue;\n }\n | TypedNode;\n\nexport type FlatContent = Record<string, FlatContentValue | undefined>;\n\nexport type ContentModule = Content & {\n id: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/types/contentModule.ts"],"sourcesContent":["import type {\n EnumerationContent,\n TranslationContent,\n} from '../transpiler/index';\n\nexport type TypedNode =\n | TranslationContent<unknown>\n | EnumerationContent<unknown>;\n\nexport type ContentValue =\n | string\n | {\n [key: string]: ContentValue;\n }\n | (() => ContentValue)\n | Promise<ContentValue>\n | TypedNode;\n\nexport type Content = Record<string, ContentValue | undefined>;\n\nexport type FlatContentValue =\n | string\n | {\n [key: string]: FlatContentValue;\n }\n | TypedNode;\n\nexport type FlatContent = Record<string, FlatContentValue | undefined>;\n\nexport type ContentModule = Content & {\n id: string;\n filePath?: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,8 +1,8 @@
1
1
  import { TranslationContent } from '../transpiler/content_transformers/translation/types.js';
2
2
  import { EnumerationContent } from '../transpiler/content_transformers/enumeration/enumeration.js';
3
- import './nodeType.js';
4
3
  import '@intlayer/config/client';
5
4
  import 'intlayer';
5
+ import './nodeType.js';
6
6
  import '../utils/getStackTraceInfo.js';
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 +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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,sBAAyB;","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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,sBAAyB;","names":[]}
@@ -1,5 +1,6 @@
1
1
  export { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode } from './contentModule.js';
2
2
  export { NodeType } from './nodeType.js';
3
+ export { KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './keyPath.js';
3
4
  import '../transpiler/content_transformers/translation/types.js';
4
5
  import '@intlayer/config/client';
5
6
  import 'intlayer';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var keyPath_exports = {};
16
+ module.exports = __toCommonJS(keyPath_exports);
17
+ //# sourceMappingURL=keyPath.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/types/keyPath.ts"],"sourcesContent":["import type { NodeType } from './nodeType';\n\nexport type ObjectExpressionNode = {\n type: 'ObjectExpression';\n key: string;\n};\n\nexport type TranslationOrEnumerationNode = {\n type: NodeType;\n key: string;\n};\n\nexport type KeyPath = ObjectExpressionNode | TranslationOrEnumerationNode;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,13 @@
1
+ import { NodeType } from './nodeType.js';
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 };
@@ -3,8 +3,10 @@ export { getTranslationContent } from './transpiler/content_transformers/transla
3
3
  export { CustomizableLanguageContent, LanguageContent, CustomLocales as Locales, TranslationContent } from './transpiler/content_transformers/translation/types.mjs';
4
4
  export { EnumerationContent, QuantityContent, enu } from './transpiler/content_transformers/enumeration/enumeration.mjs';
5
5
  export { getEnumerationContent } from './transpiler/content_transformers/enumeration/getEnumerationContent.mjs';
6
+ export { findMatchingCondition } from './transpiler/content_transformers/enumeration/findMatchingCondition.mjs';
6
7
  export { Content, ContentModule, ContentValue, FlatContent, FlatContentValue, TypedNode } from './types/contentModule.mjs';
7
8
  export { NodeType } from './types/nodeType.mjs';
9
+ export { KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './types/keyPath.mjs';
8
10
  export { getLocaleName } from './getLocaleName.mjs';
9
11
  export { localeList } from './localeList.mjs';
10
12
  import '@intlayer/config/client';
@@ -2,6 +2,7 @@ import {
2
2
  t,
3
3
  enu,
4
4
  getTranslationContent,
5
+ findMatchingCondition,
5
6
  getEnumerationContent
6
7
  } from './transpiler/content_transformers/index.mjs';
7
8
  import { NodeType } from './types/index.mjs';
@@ -10,6 +11,7 @@ import { localeList } from './localeList.mjs';
10
11
  export {
11
12
  NodeType,
12
13
  enu,
14
+ findMatchingCondition,
13
15
  getEnumerationContent,
14
16
  getLocaleName,
15
17
  getTranslationContent,