@intlayer/core 2.0.1 → 2.0.3
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.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs +2 -2
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/enumeration/enumeration.d.ts +2 -1
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs +2 -2
- package/dist/cjs/transpiler/content_transformers/translation/translation.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/types.cjs.map +1 -1
- package/dist/cjs/transpiler/content_transformers/translation/types.d.ts +2 -1
- package/dist/cjs/types/declarationContent.cjs.map +1 -1
- package/dist/cjs/types/declarationContent.d.ts +5 -6
- package/dist/cjs/types/index.cjs.map +1 -1
- package/dist/cjs/types/index.d.ts +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.d.mts +2 -1
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs +2 -2
- package/dist/esm/transpiler/content_transformers/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs +2 -2
- package/dist/esm/transpiler/content_transformers/translation/translation.mjs.map +1 -1
- package/dist/esm/transpiler/content_transformers/translation/types.d.mts +2 -1
- package/dist/esm/types/declarationContent.d.mts +5 -6
- package/dist/esm/types/index.d.mts +1 -1
- package/dist/esm/types/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +0 -1
package/dist/cjs/index.cjs.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 findMatchingCondition,\n getEnumerationContent,\n} from './transpiler/content_transformers/index';\nexport type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n DeclarationContent,\n
|
|
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 DeclarationContent,\n KeyPath,\n ObjectExpressionNode,\n ArrayExpressionNode,\n TranslationOrEnumerationNode,\n DictionaryValue,\n Dictionary,\n} from './types/index';\nexport { NodeType } from './types/index';\nexport { getLocaleName } from './getLocaleName';\nexport { localeList } from './localeList';\nexport { isSameKeyPath } from './utils/isSameKeyPath';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,kCAMO;AAeP,mBAAyB;AACzB,2BAA8B;AAC9B,wBAA2B;AAC3B,2BAA8B;","names":[]}
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { CustomizableLanguageContent, LanguageContent, CustomLocales as Locales,
|
|
|
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
6
|
export { findMatchingCondition } from './transpiler/content_transformers/enumeration/findMatchingCondition.js';
|
|
7
|
-
export { Content, ContentValue,
|
|
7
|
+
export { Content, ContentValue, DeclarationContent, FlatContent, FlatContentValue, TypedNode } from './types/declarationContent.js';
|
|
8
8
|
export { NodeType } from './types/nodeType.js';
|
|
9
9
|
export { ArrayExpressionNode, KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './types/keyPath.js';
|
|
10
10
|
export { Dictionary, DictionaryValue } from './types/dictionary.js';
|
|
@@ -26,13 +26,13 @@ const enumeration = (content) => {
|
|
|
26
26
|
if (typeof content === "string") {
|
|
27
27
|
const result2 = {
|
|
28
28
|
nodeType: import_types.NodeType.Enumeration,
|
|
29
|
-
1: content
|
|
29
|
+
[import_types.NodeType.Enumeration]: { 1: content }
|
|
30
30
|
};
|
|
31
31
|
return result2;
|
|
32
32
|
}
|
|
33
33
|
const result = {
|
|
34
34
|
nodeType: import_types.NodeType.Enumeration,
|
|
35
|
-
...content
|
|
35
|
+
[import_types.NodeType.Enumeration]: { ...content }
|
|
36
36
|
};
|
|
37
37
|
return result;
|
|
38
38
|
};
|
|
@@ -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';\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> =
|
|
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> = {\n nodeType: NodeType.Enumeration;\n [NodeType.Enumeration]: Partial<QuantityContent<Content>>;\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 [NodeType.Enumeration]: { 1: content },\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: { ...content },\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAyB;AA+CzB,MAAM,cAAc,CAAU,YAAgD;AAC5E,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,sBAAS;AAAA,MACnB,CAAC,sBAAS,WAAW,GAAG,EAAE,GAAG,QAAQ;AAAA,IACvC;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,CAAC,sBAAS,WAAW,GAAG,EAAE,GAAG,QAAQ;AAAA,EACvC;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -11,8 +11,9 @@ type Inferior = `<${Numbers}`;
|
|
|
11
11
|
type InferiorOrEqual = `<=${Numbers}`;
|
|
12
12
|
type EnterFormat = Equal | EqualString | Superior | SuperiorOrEqual | Inferior | InferiorOrEqual;
|
|
13
13
|
type QuantityContent<Content> = Record<EnterFormat, Content>;
|
|
14
|
-
type EnumerationContent<Content> =
|
|
14
|
+
type EnumerationContent<Content> = {
|
|
15
15
|
nodeType: NodeType.Enumeration;
|
|
16
|
+
[NodeType.Enumeration]: Partial<QuantityContent<Content>>;
|
|
16
17
|
};
|
|
17
18
|
/**
|
|
18
19
|
* Function intended to be used to build intlayer dictionaries.
|
|
@@ -30,13 +30,13 @@ const translation = (content) => {
|
|
|
30
30
|
if (typeof content === "string") {
|
|
31
31
|
const result2 = {
|
|
32
32
|
nodeType: import_types.NodeType.Translation,
|
|
33
|
-
[defaultLocale]: content
|
|
33
|
+
[import_types.NodeType.Translation]: { [defaultLocale]: content }
|
|
34
34
|
};
|
|
35
35
|
return result2;
|
|
36
36
|
}
|
|
37
37
|
const result = {
|
|
38
38
|
nodeType: import_types.NodeType.Translation,
|
|
39
|
-
|
|
39
|
+
[import_types.NodeType.Translation]: content
|
|
40
40
|
};
|
|
41
41
|
return result;
|
|
42
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport 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
|
|
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 [NodeType.Translation]: { [defaultLocale]: content },\n } as TranslationContent<Content>;\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: content,\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,sBAAS,WAAW,GAAG,EAAE,CAAC,aAAa,GAAG,QAAQ;AAAA,IACrD;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,sBAAS;AAAA,IACnB,CAAC,sBAAS,WAAW,GAAG;AAAA,EAC1B;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -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';\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> =
|
|
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';\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> = {\n nodeType: NodeType.Translation;\n [NodeType.Translation]: LanguageContent<Content>;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -54,8 +54,9 @@ type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;
|
|
|
54
54
|
*
|
|
55
55
|
*/
|
|
56
56
|
type CustomizableLanguageContent<Content = string> = ConfigLocales extends never ? LanguageContent<Content> : IConfigLocales<Content>;
|
|
57
|
-
type TranslationContent<Content> =
|
|
57
|
+
type TranslationContent<Content> = {
|
|
58
58
|
nodeType: NodeType.Translation;
|
|
59
|
+
[NodeType.Translation]: LanguageContent<Content>;
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
export type { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/declarationContent.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type {\n EnumerationContent,\n TranslationContent,\n} from '../transpiler/index';\n\nexport type TypedNode =\n | TranslationContent<unknown>\n | EnumerationContent<unknown>;\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/types/declarationContent.ts"],"sourcesContent":["import type { ReactNode } from 'react';\nimport 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 | string[]\n | number\n | number[]\n | {\n [key: string]: ContentValue;\n }\n | (() => ContentValue)\n | Promise<ContentValue>\n | TypedNode;\n\nexport type Content = Record<string, ContentValue | 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\n// Utility type that performs recursive replacement\ntype ReplaceContentValue<T> = {\n [P in keyof T]: T[P] extends string | number | boolean | null | ReactNode\n ? ContentValue\n : T[P] extends object\n ? ReplaceContentValue<T[P]>\n : ReplaceContentValueArray<T[P]>;\n};\n\ntype ReplaceContentValueArray<T> = T extends (infer U)[]\n ? ReplaceContentValue<U>[]\n : ReplaceContentValue<T>;\n\nexport type DeclarationContent<T = undefined> = (T extends undefined // Applying the generic to replace ContentValue with Replacement\n ? Content\n : ReplaceContentValue<T>) & {\n id: string;\n filePath?: string;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -6,22 +6,21 @@ import 'intlayer';
|
|
|
6
6
|
import './nodeType.js';
|
|
7
7
|
|
|
8
8
|
type TypedNode = TranslationContent<unknown> | EnumerationContent<unknown>;
|
|
9
|
-
type
|
|
10
|
-
type ContentValueArray = ArrayOfSameType<ContentValue[]>;
|
|
11
|
-
type ContentValue = string | {
|
|
9
|
+
type ContentValue = string | string[] | number | number[] | {
|
|
12
10
|
[key: string]: ContentValue;
|
|
13
11
|
} | (() => ContentValue) | Promise<ContentValue> | TypedNode;
|
|
14
|
-
type Content = Record<string, ContentValue |
|
|
12
|
+
type Content = Record<string, ContentValue | ContentValue[] | undefined>;
|
|
15
13
|
type FlatContentValue = string | {
|
|
16
14
|
[key: string]: FlatContentValue;
|
|
17
15
|
} | TypedNode;
|
|
18
16
|
type FlatContent = Record<string, FlatContentValue | undefined>;
|
|
19
17
|
type ReplaceContentValue<T> = {
|
|
20
|
-
[P in keyof T]: T[P] extends string | number | boolean | null | ReactNode ? ContentValue : T[P] extends object ? ReplaceContentValue<T[P]> : T[P]
|
|
18
|
+
[P in keyof T]: T[P] extends string | number | boolean | null | ReactNode ? ContentValue : T[P] extends object ? ReplaceContentValue<T[P]> : ReplaceContentValueArray<T[P]>;
|
|
21
19
|
};
|
|
20
|
+
type ReplaceContentValueArray<T> = T extends (infer U)[] ? ReplaceContentValue<U>[] : ReplaceContentValue<T>;
|
|
22
21
|
type DeclarationContent<T = undefined> = (T extends undefined ? Content : ReplaceContentValue<T>) & {
|
|
23
22
|
id: string;
|
|
24
23
|
filePath?: string;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
export type { Content, ContentValue,
|
|
26
|
+
export type { Content, ContentValue, DeclarationContent, FlatContent, FlatContentValue, TypedNode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n ContentValue,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n DeclarationContent,\n} from './declarationContent';\nexport { NodeType } from './nodeType';\nexport type {\n KeyPath,\n ObjectExpressionNode,\n ArrayExpressionNode,\n TranslationOrEnumerationNode,\n} from './keyPath';\nexport type { DictionaryValue, Dictionary } from './dictionary';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,sBAAyB;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Content, ContentValue,
|
|
1
|
+
export { Content, ContentValue, DeclarationContent, FlatContent, FlatContentValue, TypedNode } from './declarationContent.js';
|
|
2
2
|
export { NodeType } from './nodeType.js';
|
|
3
3
|
export { ArrayExpressionNode, KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './keyPath.js';
|
|
4
4
|
export { Dictionary, DictionaryValue } from './dictionary.js';
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ export { CustomizableLanguageContent, LanguageContent, CustomLocales as Locales,
|
|
|
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
6
|
export { findMatchingCondition } from './transpiler/content_transformers/enumeration/findMatchingCondition.mjs';
|
|
7
|
-
export { Content, ContentValue,
|
|
7
|
+
export { Content, ContentValue, DeclarationContent, FlatContent, FlatContentValue, TypedNode } from './types/declarationContent.mjs';
|
|
8
8
|
export { NodeType } from './types/nodeType.mjs';
|
|
9
9
|
export { ArrayExpressionNode, KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './types/keyPath.mjs';
|
|
10
10
|
export { Dictionary, DictionaryValue } from './types/dictionary.mjs';
|
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 findMatchingCondition,\n getEnumerationContent,\n} from './transpiler/content_transformers/index';\nexport type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n DeclarationContent,\n
|
|
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 DeclarationContent,\n KeyPath,\n ObjectExpressionNode,\n ArrayExpressionNode,\n TranslationOrEnumerationNode,\n DictionaryValue,\n Dictionary,\n} from './types/index';\nexport { NodeType } from './types/index';\nexport { getLocaleName } from './getLocaleName';\nexport { localeList } from './localeList';\nexport { isSameKeyPath } from './utils/isSameKeyPath';\n"],"mappings":"AAQA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;","names":[]}
|
|
@@ -11,8 +11,9 @@ type Inferior = `<${Numbers}`;
|
|
|
11
11
|
type InferiorOrEqual = `<=${Numbers}`;
|
|
12
12
|
type EnterFormat = Equal | EqualString | Superior | SuperiorOrEqual | Inferior | InferiorOrEqual;
|
|
13
13
|
type QuantityContent<Content> = Record<EnterFormat, Content>;
|
|
14
|
-
type EnumerationContent<Content> =
|
|
14
|
+
type EnumerationContent<Content> = {
|
|
15
15
|
nodeType: NodeType.Enumeration;
|
|
16
|
+
[NodeType.Enumeration]: Partial<QuantityContent<Content>>;
|
|
16
17
|
};
|
|
17
18
|
/**
|
|
18
19
|
* Function intended to be used to build intlayer dictionaries.
|
|
@@ -3,13 +3,13 @@ const enumeration = (content) => {
|
|
|
3
3
|
if (typeof content === "string") {
|
|
4
4
|
const result2 = {
|
|
5
5
|
nodeType: NodeType.Enumeration,
|
|
6
|
-
1: content
|
|
6
|
+
[NodeType.Enumeration]: { 1: content }
|
|
7
7
|
};
|
|
8
8
|
return result2;
|
|
9
9
|
}
|
|
10
10
|
const result = {
|
|
11
11
|
nodeType: NodeType.Enumeration,
|
|
12
|
-
...content
|
|
12
|
+
[NodeType.Enumeration]: { ...content }
|
|
13
13
|
};
|
|
14
14
|
return result;
|
|
15
15
|
};
|
|
@@ -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';\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> =
|
|
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> = {\n nodeType: NodeType.Enumeration;\n [NodeType.Enumeration]: Partial<QuantityContent<Content>>;\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 [NodeType.Enumeration]: { 1: content },\n };\n\n return result;\n }\n\n const result: EnumerationContent<Content> = {\n nodeType: NodeType.Enumeration,\n [NodeType.Enumeration]: { ...content },\n };\n\n return result;\n};\n\nexport { enumeration as enu };\n"],"mappings":"AACA,SAAS,gBAAgB;AA+CzB,MAAM,cAAc,CAAU,YAAgD;AAC5E,MAAI,OAAO,YAAY,UAAU;AAC/B,UAAMA,UAAsC;AAAA,MAC1C,UAAU,SAAS;AAAA,MACnB,CAAC,SAAS,WAAW,GAAG,EAAE,GAAG,QAAQ;AAAA,IACvC;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,CAAC,SAAS,WAAW,GAAG,EAAE,GAAG,QAAQ;AAAA,EACvC;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -7,13 +7,13 @@ const translation = (content) => {
|
|
|
7
7
|
if (typeof content === "string") {
|
|
8
8
|
const result2 = {
|
|
9
9
|
nodeType: NodeType.Translation,
|
|
10
|
-
[defaultLocale]: content
|
|
10
|
+
[NodeType.Translation]: { [defaultLocale]: content }
|
|
11
11
|
};
|
|
12
12
|
return result2;
|
|
13
13
|
}
|
|
14
14
|
const result = {
|
|
15
15
|
nodeType: NodeType.Translation,
|
|
16
|
-
|
|
16
|
+
[NodeType.Translation]: content
|
|
17
17
|
};
|
|
18
18
|
return result;
|
|
19
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/transpiler/content_transformers/translation/translation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { NodeType } from '../../../types/index';\nimport 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
|
|
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 [NodeType.Translation]: { [defaultLocale]: content },\n } as TranslationContent<Content>;\n\n return result;\n }\n\n const result: TranslationContent<Content> = {\n nodeType: NodeType.Translation,\n [NodeType.Translation]: content,\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,SAAS,WAAW,GAAG,EAAE,CAAC,aAAa,GAAG,QAAQ;AAAA,IACrD;AAEA,WAAOA;AAAA,EACT;AAEA,QAAM,SAAsC;AAAA,IAC1C,UAAU,SAAS;AAAA,IACnB,CAAC,SAAS,WAAW,GAAG;AAAA,EAC1B;AAEA,SAAO;AACT;","names":["result"]}
|
|
@@ -54,8 +54,9 @@ type LanguageContent<Content> = Partial<Record<LocalesValues, Content>>;
|
|
|
54
54
|
*
|
|
55
55
|
*/
|
|
56
56
|
type CustomizableLanguageContent<Content = string> = ConfigLocales extends never ? LanguageContent<Content> : IConfigLocales<Content>;
|
|
57
|
-
type TranslationContent<Content> =
|
|
57
|
+
type TranslationContent<Content> = {
|
|
58
58
|
nodeType: NodeType.Translation;
|
|
59
|
+
[NodeType.Translation]: LanguageContent<Content>;
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
export type { ConfigLocales, CustomLocales, CustomizableLanguageContent, LanguageContent, TranslationContent };
|
|
@@ -6,22 +6,21 @@ import 'intlayer';
|
|
|
6
6
|
import './nodeType.mjs';
|
|
7
7
|
|
|
8
8
|
type TypedNode = TranslationContent<unknown> | EnumerationContent<unknown>;
|
|
9
|
-
type
|
|
10
|
-
type ContentValueArray = ArrayOfSameType<ContentValue[]>;
|
|
11
|
-
type ContentValue = string | {
|
|
9
|
+
type ContentValue = string | string[] | number | number[] | {
|
|
12
10
|
[key: string]: ContentValue;
|
|
13
11
|
} | (() => ContentValue) | Promise<ContentValue> | TypedNode;
|
|
14
|
-
type Content = Record<string, ContentValue |
|
|
12
|
+
type Content = Record<string, ContentValue | ContentValue[] | undefined>;
|
|
15
13
|
type FlatContentValue = string | {
|
|
16
14
|
[key: string]: FlatContentValue;
|
|
17
15
|
} | TypedNode;
|
|
18
16
|
type FlatContent = Record<string, FlatContentValue | undefined>;
|
|
19
17
|
type ReplaceContentValue<T> = {
|
|
20
|
-
[P in keyof T]: T[P] extends string | number | boolean | null | ReactNode ? ContentValue : T[P] extends object ? ReplaceContentValue<T[P]> : T[P]
|
|
18
|
+
[P in keyof T]: T[P] extends string | number | boolean | null | ReactNode ? ContentValue : T[P] extends object ? ReplaceContentValue<T[P]> : ReplaceContentValueArray<T[P]>;
|
|
21
19
|
};
|
|
20
|
+
type ReplaceContentValueArray<T> = T extends (infer U)[] ? ReplaceContentValue<U>[] : ReplaceContentValue<T>;
|
|
22
21
|
type DeclarationContent<T = undefined> = (T extends undefined ? Content : ReplaceContentValue<T>) & {
|
|
23
22
|
id: string;
|
|
24
23
|
filePath?: string;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
export type { Content, ContentValue,
|
|
26
|
+
export type { Content, ContentValue, DeclarationContent, FlatContent, FlatContentValue, TypedNode };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Content, ContentValue,
|
|
1
|
+
export { Content, ContentValue, DeclarationContent, FlatContent, FlatContentValue, TypedNode } from './declarationContent.mjs';
|
|
2
2
|
export { NodeType } from './nodeType.mjs';
|
|
3
3
|
export { ArrayExpressionNode, KeyPath, ObjectExpressionNode, TranslationOrEnumerationNode } from './keyPath.mjs';
|
|
4
4
|
export { Dictionary, DictionaryValue } from './dictionary.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n ContentValue,\n
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n ContentValue,\n Content,\n FlatContentValue,\n FlatContent,\n TypedNode,\n DeclarationContent,\n} from './declarationContent';\nexport { NodeType } from './nodeType';\nexport type {\n KeyPath,\n ObjectExpressionNode,\n ArrayExpressionNode,\n TranslationOrEnumerationNode,\n} from './keyPath';\nexport type { DictionaryValue, Dictionary } from './dictionary';\n"],"mappings":"AAQA,SAAS,gBAAgB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "IntLayer - Layer of abstraction between the business logic and the data access layer. Manage internationalization in a simple way, through TypeScript, JavaScript or JSON declaration file.",
|
|
6
6
|
"keywords": [
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"chokidar": "^3.6.0",
|
|
53
|
-
"@intlayer/config": "^2.0.
|
|
53
|
+
"@intlayer/config": "^2.0.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^20.
|
|
57
|
-
"@types/react": "^18.
|
|
58
|
-
"react": "^18.
|
|
56
|
+
"@types/node": "^20.14.9",
|
|
57
|
+
"@types/react": "^18.3.3",
|
|
58
|
+
"react": "^18.3.1",
|
|
59
59
|
"rimraf": "5.0.5",
|
|
60
|
-
"tsup": "^8.0
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"@utils/eslint-config": "^1.0.
|
|
63
|
-
"@utils/ts-config": "^1.0.
|
|
60
|
+
"tsup": "^8.1.0",
|
|
61
|
+
"typescript": "^5.5.2",
|
|
62
|
+
"@utils/eslint-config": "^1.0.3",
|
|
63
|
+
"@utils/ts-config": "^1.0.3"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"react": "^18.2.0"
|