@intlayer/core 5.8.1 → 6.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/deepTranformPlugins/getFilterTranslationsOnlyContent.cjs +130 -0
- package/dist/cjs/deepTranformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -0
- package/dist/cjs/deepTranformPlugins/getFilteredLocalesContent.cjs +62 -0
- package/dist/cjs/deepTranformPlugins/getFilteredLocalesContent.cjs.map +1 -0
- package/dist/cjs/{interpreter/getContent → deepTranformPlugins}/getLocalisedContent.cjs +3 -3
- package/dist/cjs/deepTranformPlugins/getLocalisedContent.cjs.map +1 -0
- package/dist/cjs/deepTranformPlugins/getMissingLocalesContent.cjs +78 -0
- package/dist/cjs/deepTranformPlugins/getMissingLocalesContent.cjs.map +1 -0
- package/dist/cjs/deepTranformPlugins/getReplacedValuesContent.cjs +82 -0
- package/dist/cjs/deepTranformPlugins/getReplacedValuesContent.cjs.map +1 -0
- package/dist/cjs/deepTranformPlugins/index.cjs +31 -0
- package/dist/cjs/deepTranformPlugins/index.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
- package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
- package/dist/cjs/dictionaryManipulator/getUnmergedDictionaryByKeyPath.cjs +52 -0
- package/dist/cjs/dictionaryManipulator/getUnmergedDictionaryByKeyPath.cjs.map +1 -0
- package/dist/cjs/dictionaryManipulator/index.cjs +9 -7
- package/dist/cjs/dictionaryManipulator/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/index.cjs +0 -2
- package/dist/cjs/interpreter/getContent/index.cjs.map +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs +1 -1
- package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
- package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
- package/dist/cjs/interpreter/getTranslation.cjs +3 -15
- package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
- package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
- package/dist/cjs/transpiler/file/file.cjs +4 -1
- package/dist/cjs/transpiler/file/file.cjs.map +1 -1
- package/dist/cjs/types/dictionary.cjs.map +1 -1
- package/dist/cjs/types/intlayer.cjs +35 -0
- package/dist/cjs/types/intlayer.cjs.map +1 -0
- package/dist/cjs/types/translation.cjs.map +1 -1
- package/dist/cjs/utils/intl.cjs +2 -15
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/esm/deepTranformPlugins/getFilterTranslationsOnlyContent.mjs +95 -0
- package/dist/esm/deepTranformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -0
- package/dist/esm/deepTranformPlugins/getFilteredLocalesContent.mjs +40 -0
- package/dist/esm/deepTranformPlugins/getFilteredLocalesContent.mjs.map +1 -0
- package/dist/esm/{interpreter/getContent → deepTranformPlugins}/getLocalisedContent.mjs +3 -3
- package/dist/esm/deepTranformPlugins/getLocalisedContent.mjs.map +1 -0
- package/dist/esm/deepTranformPlugins/getMissingLocalesContent.mjs +43 -0
- package/dist/esm/deepTranformPlugins/getMissingLocalesContent.mjs.map +1 -0
- package/dist/esm/deepTranformPlugins/getReplacedValuesContent.mjs +60 -0
- package/dist/esm/deepTranformPlugins/getReplacedValuesContent.mjs.map +1 -0
- package/dist/esm/deepTranformPlugins/index.mjs +6 -0
- package/dist/esm/deepTranformPlugins/index.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
- package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
- package/dist/esm/dictionaryManipulator/getUnmergedDictionaryByKeyPath.mjs +18 -0
- package/dist/esm/dictionaryManipulator/getUnmergedDictionaryByKeyPath.mjs.map +1 -0
- package/dist/esm/dictionaryManipulator/index.mjs +4 -3
- package/dist/esm/dictionaryManipulator/index.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/index.mjs +0 -1
- package/dist/esm/interpreter/getContent/index.mjs.map +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs +1 -1
- package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
- package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
- package/dist/esm/interpreter/getTranslation.mjs +3 -5
- package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
- package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
- package/dist/esm/transpiler/file/file.mjs +5 -2
- package/dist/esm/transpiler/file/file.mjs.map +1 -1
- package/dist/esm/types/intlayer.mjs +13 -0
- package/dist/esm/types/intlayer.mjs.map +1 -0
- package/dist/esm/utils/intl.mjs +2 -5
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.d.ts +13 -0
- package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.test.d.ts +2 -0
- package/dist/types/deepTranformPlugins/getFilterTranslationsOnlyContent.test.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/getFilteredLocalesContent.d.ts +5 -0
- package/dist/types/deepTranformPlugins/getFilteredLocalesContent.d.ts.map +1 -0
- package/dist/types/{interpreter/getContent → deepTranformPlugins}/getLocalisedContent.d.ts +3 -3
- package/dist/types/deepTranformPlugins/getLocalisedContent.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/getMissingLocalesContent.d.ts +13 -0
- package/dist/types/deepTranformPlugins/getMissingLocalesContent.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/getMissingLocalesContent.test.d.ts +2 -0
- package/dist/types/deepTranformPlugins/getMissingLocalesContent.test.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/getReplacedValuesContent.d.ts +4 -0
- package/dist/types/deepTranformPlugins/getReplacedValuesContent.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/getReplacedValuesContent.test.d.ts +2 -0
- package/dist/types/deepTranformPlugins/getReplacedValuesContent.test.d.ts.map +1 -0
- package/dist/types/deepTranformPlugins/index.d.ts +6 -0
- package/dist/types/deepTranformPlugins/index.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts +4 -0
- package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts.map +1 -0
- package/dist/types/dictionaryManipulator/index.d.ts +4 -3
- package/dist/types/dictionaryManipulator/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/index.d.ts +0 -1
- package/dist/types/interpreter/getContent/index.d.ts.map +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts +1 -1
- package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts +1 -1
- package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
- package/dist/types/interpreter/getTranslation.d.ts +1 -1
- package/dist/types/interpreter/getTranslation.d.ts.map +1 -1
- package/dist/types/transpiler/enumeration/enumeration.d.ts +3 -3
- package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
- package/dist/types/transpiler/file/file.d.ts.map +1 -1
- package/dist/types/types/dictionary.d.ts +252 -2
- package/dist/types/types/dictionary.d.ts.map +1 -1
- package/dist/types/types/intlayer.d.ts +5 -0
- package/dist/types/types/intlayer.d.ts.map +1 -0
- package/dist/types/types/translation.d.ts +1 -2
- package/dist/types/types/translation.d.ts.map +1 -1
- package/dist/types/utils/intl.d.ts +1 -1
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/package.json +13 -11
- package/dist/cjs/interpreter/getContent/getLocalisedContent.cjs.map +0 -1
- package/dist/esm/interpreter/getContent/getLocalisedContent.mjs.map +0 -1
- package/dist/types/interpreter/getContent/getLocalisedContent.d.ts.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
deepTransformNode
|
|
3
|
+
} from "../interpreter/index.mjs";
|
|
4
|
+
const replaceValuesPlugin = (value) => ({
|
|
5
|
+
id: "replace-values-plugin",
|
|
6
|
+
canHandle: (node) => typeof node === "string" || typeof node === "number" || typeof node === "boolean",
|
|
7
|
+
transform: () => value
|
|
8
|
+
});
|
|
9
|
+
const skipTypedNodePlugin = {
|
|
10
|
+
id: "skip-typed-node-plugin",
|
|
11
|
+
canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
|
|
12
|
+
transform: (node, props, deepTransformNode2) => {
|
|
13
|
+
const nodeType = node.nodeType;
|
|
14
|
+
const result = structuredClone(
|
|
15
|
+
node[nodeType]
|
|
16
|
+
);
|
|
17
|
+
if (typeof result !== "object" || result === null) {
|
|
18
|
+
const transformedResult = deepTransformNode2(result, {
|
|
19
|
+
...props,
|
|
20
|
+
children: result,
|
|
21
|
+
keyPath: [
|
|
22
|
+
...props.keyPath,
|
|
23
|
+
{ type: nodeType, key: nodeType }
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
...node,
|
|
28
|
+
[nodeType]: transformedResult
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
for (const key in result) {
|
|
32
|
+
const childProps = {
|
|
33
|
+
...props,
|
|
34
|
+
children: result[key],
|
|
35
|
+
keyPath: [...props.keyPath, { type: nodeType, key }]
|
|
36
|
+
};
|
|
37
|
+
result[key] = deepTransformNode2(
|
|
38
|
+
result[key],
|
|
39
|
+
childProps
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return { ...node, [nodeType]: result };
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const getReplacedValuesContent = (node, value, nodeProps) => {
|
|
46
|
+
const plugins = [
|
|
47
|
+
skipTypedNodePlugin,
|
|
48
|
+
replaceValuesPlugin(value),
|
|
49
|
+
...nodeProps.plugins ?? []
|
|
50
|
+
];
|
|
51
|
+
const JSONNode = JSON.parse(JSON.stringify(node));
|
|
52
|
+
return deepTransformNode(JSONNode, {
|
|
53
|
+
...nodeProps,
|
|
54
|
+
plugins
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
getReplacedValuesContent
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=getReplacedValuesContent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/deepTranformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { KeyPath, NodeType, TypedNode, type ContentNode } from '../types';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"AAAA;AAAA,EACE;AAAA,OAGK;AAGP,MAAM,sBAAsB,CAAC,WAA+C;AAAA,EAC1E,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;AAAA,EAClB,WAAW,MAAM;AACnB;AAEA,MAAM,sBAA+B;AAAA,EACnC,IAAI;AAAA,EACJ,WAAW,CAAC,SACV,OAAO,SAAS,YAAY,OAAO,MAAM,aAAa;AAAA,EACxD,WAAW,CAAC,MAAiB,OAAOA,uBAAsB;AACxD,UAAM,WAAW,KAAK;AACtB,UAAM,SAAS;AAAA,MACb,KAAK,QAAsC;AAAA,IAC7C;AAIA,QAAI,OAAO,WAAW,YAAY,WAAW,MAAM;AACjD,YAAM,oBAAoBA,mBAAkB,QAAQ;AAAA,QAClD,GAAG;AAAA,QACH,UAAU;AAAA,QACV,SAAS;AAAA,UACP,GAAG,MAAM;AAAA,UACT,EAAE,MAAM,UAAU,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,CAAC;AACD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,CAAC,QAAsC,GAAG;AAAA,MAC5C;AAAA,IACF;AAGA,eAAW,OAAO,QAAQ;AACxB,YAAM,aAAa;AAAA,QACjB,GAAG;AAAA,QACH,UAAU,OAAO,GAAqC;AAAA,QACtD,SAAS,CAAC,GAAG,MAAM,SAAS,EAAE,MAAM,UAAU,IAAI,CAAY;AAAA,MAChE;AACA,aAAO,GAAqC,IAAIA;AAAA,QAC9C,OAAO,GAAqC;AAAA,QAC5C;AAAA,MACF;AAAA,IACF;AAEA,WAAO,EAAE,GAAG,MAAM,CAAC,QAAsC,GAAG,OAAO;AAAA,EACrE;AACF;AAEO,MAAM,2BAA2B,CACtC,MACA,OACA,cACG;AACH,QAAM,UAAqB;AAAA,IACzB;AAAA,IACA,oBAAoB,KAAK;AAAA,IACzB,GAAI,UAAU,WAAW,CAAC;AAAA,EAC5B;AAEA,QAAM,WAAW,KAAK,MAAM,KAAK,UAAU,IAAI,CAAC;AAEhD,SAAO,kBAAkB,UAAU;AAAA,IACjC,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AACH;","names":["deepTransformNode"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./getFilteredLocalesContent.mjs";
|
|
2
|
+
export * from "./getFilterTranslationsOnlyContent.mjs";
|
|
3
|
+
export * from "./getLocalisedContent.mjs";
|
|
4
|
+
export * from "./getMissingLocalesContent.mjs";
|
|
5
|
+
export * from "./getReplacedValuesContent.mjs";
|
|
6
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/deepTranformPlugins/index.ts"],"sourcesContent":["export * from './getFilteredLocalesContent';\nexport * from './getFilterTranslationsOnlyContent';\nexport * from './getLocalisedContent';\nexport * from './getMissingLocalesContent';\nexport * from './getReplacedValuesContent';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -12,7 +12,7 @@ const getNodeChildren = (section) => {
|
|
|
12
12
|
if (typeof section?.nodeType === "string") {
|
|
13
13
|
const typedNode = section;
|
|
14
14
|
const content = typedNode[typedNode.nodeType];
|
|
15
|
-
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion || typedNode.nodeType === NodeType.File) {
|
|
15
|
+
if (typedNode.nodeType === NodeType.Translation || typedNode.nodeType === NodeType.Enumeration || typedNode.nodeType === NodeType.Condition || typedNode.nodeType === NodeType.Insertion || typedNode.nodeType === NodeType.Gender || typedNode.nodeType === NodeType.File || typedNode.nodeType === NodeType.Markdown) {
|
|
16
16
|
const firstKey = Object.keys(content)[0];
|
|
17
17
|
return content[firstKey];
|
|
18
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.File\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":"AAAA,SAA2C,gBAAgB;AAEpD,MAAM,kBAAkB,CAAC,YAAsC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"sourcesContent":["import { type ContentNode, type TypedNode, NodeType } from '../types';\n\nexport const getNodeChildren = (section: ContentNode): ContentNode => {\n if (typeof section === 'string') {\n return section;\n }\n if (typeof section === 'number') {\n return section;\n }\n if (typeof section === 'boolean') {\n return section;\n }\n if (typeof (section as TypedNode)?.nodeType === 'string') {\n const typedNode = section as TypedNode;\n const content = typedNode[typedNode.nodeType as keyof TypedNode];\n\n if (\n typedNode.nodeType === NodeType.Translation ||\n typedNode.nodeType === NodeType.Enumeration ||\n typedNode.nodeType === NodeType.Condition ||\n typedNode.nodeType === NodeType.Insertion ||\n typedNode.nodeType === NodeType.Gender ||\n typedNode.nodeType === NodeType.File ||\n typedNode.nodeType === NodeType.Markdown\n ) {\n const firstKey = Object.keys(content)[0] as keyof typeof content;\n return content[firstKey] as ContentNode;\n }\n\n if (typedNode.nodeType === NodeType.Nested) {\n return undefined;\n }\n\n return content;\n }\n\n if (!section || typeof section !== 'object') {\n return section;\n }\n\n if (Array.isArray(section)) {\n return (section as ContentNode[])[0];\n }\n\n return section;\n};\n"],"mappings":"AAAA,SAA2C,gBAAgB;AAEpD,MAAM,kBAAkB,CAAC,YAAsC;AACpE,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,YAAY,WAAW;AAChC,WAAO;AAAA,EACT;AACA,MAAI,OAAQ,SAAuB,aAAa,UAAU;AACxD,UAAM,YAAY;AAClB,UAAM,UAAU,UAAU,UAAU,QAA2B;AAE/D,QACE,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,eAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,aAChC,UAAU,aAAa,SAAS,UAChC,UAAU,aAAa,SAAS,QAChC,UAAU,aAAa,SAAS,UAChC;AACA,YAAM,WAAW,OAAO,KAAK,OAAO,EAAE,CAAC;AACvC,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,QAAI,UAAU,aAAa,SAAS,QAAQ;AAC1C,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,WAAQ,QAA0B,CAAC;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import unmergedDictionary from "@intlayer/unmerged-dictionaries-entry";
|
|
2
|
+
import { getContentNodeByKeyPath } from "./getContentNodeByKeyPath.mjs";
|
|
3
|
+
const getUnmergedDictionaryByKeyPath = (dictionaryKey, keyPath, dictionariesRecord = unmergedDictionary) => {
|
|
4
|
+
const unmergedEntries = dictionariesRecord?.[dictionaryKey];
|
|
5
|
+
if (!unmergedEntries) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
for (const dictionary of unmergedEntries) {
|
|
9
|
+
const content = getContentNodeByKeyPath(dictionary.content, keyPath);
|
|
10
|
+
if (content) {
|
|
11
|
+
return dictionary;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
getUnmergedDictionaryByKeyPath
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=getUnmergedDictionaryByKeyPath.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/getUnmergedDictionaryByKeyPath.ts"],"sourcesContent":["import unmergedDictionary from '@intlayer/unmerged-dictionaries-entry';\nimport { type KeyPath } from '../types';\nimport { getContentNodeByKeyPath } from './getContentNodeByKeyPath';\n\nexport const getUnmergedDictionaryByKeyPath = (\n dictionaryKey: string,\n keyPath: KeyPath[],\n dictionariesRecord: keyof typeof unmergedDictionary = unmergedDictionary\n) => {\n const unmergedEntries = dictionariesRecord?.[dictionaryKey];\n\n if (!unmergedEntries) {\n return null;\n }\n\n for (const dictionary of unmergedEntries) {\n const content = getContentNodeByKeyPath(dictionary.content, keyPath);\n\n if (content) {\n return dictionary;\n }\n }\n};\n"],"mappings":"AAAA,OAAO,wBAAwB;AAE/B,SAAS,+BAA+B;AAEjC,MAAM,iCAAiC,CAC5C,eACA,SACA,qBAAsD,uBACnD;AACH,QAAM,kBAAkB,qBAAqB,aAAa;AAE1D,MAAI,CAAC,iBAAiB;AACpB,WAAO;AAAA,EACT;AAEA,aAAW,cAAc,iBAAiB;AACxC,UAAM,UAAU,wBAAwB,WAAW,SAAS,OAAO;AAEnE,QAAI,SAAS;AACX,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from "./editDictionaryByKeyPath.mjs";
|
|
2
2
|
export * from "./getContentNodeByKeyPath.mjs";
|
|
3
|
+
export * from "./getDefaultNode.mjs";
|
|
4
|
+
export * from "./getEmptyNode.mjs";
|
|
3
5
|
export * from "./getNodeChildren.mjs";
|
|
6
|
+
export * from "./getNodeType.mjs";
|
|
7
|
+
export * from "./getUnmergedDictionaryByKeyPath.mjs";
|
|
4
8
|
export * from "./removeContentNodeByKeyPath.mjs";
|
|
5
9
|
export * from "./renameContentNodeByKeyPath.mjs";
|
|
6
|
-
export * from "./getNodeType.mjs";
|
|
7
10
|
export * from "./updateNodeChildren.mjs";
|
|
8
|
-
export * from "./getDefaultNode.mjs";
|
|
9
|
-
export * from "./getEmptyNode.mjs";
|
|
10
11
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getContentNodeByKeyPath';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../src/dictionaryManipulator/index.ts"],"sourcesContent":["export * from './editDictionaryByKeyPath';\nexport * from './getContentNodeByKeyPath';\nexport * from './getDefaultNode';\nexport * from './getEmptyNode';\nexport * from './getNodeChildren';\nexport * from './getNodeType';\nexport * from './getUnmergedDictionaryByKeyPath';\nexport * from './removeContentNodeByKeyPath';\nexport * from './renameContentNodeByKeyPath';\nexport * from './updateNodeChildren';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './formatters/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/intl';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './deepTranformPlugins';\nexport * from './dictionaryManipulator/index';\nexport * from './formatters/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/intl';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './getContent';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/index.ts"],"sourcesContent":["export * from './deepTransform';\nexport * from './getContent';\nexport * from './plugins';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -5,7 +5,7 @@ import { getGender } from "../getGender.mjs";
|
|
|
5
5
|
import { getInsertion } from "../getInsertion.mjs";
|
|
6
6
|
import { getNesting } from "../getNesting.mjs";
|
|
7
7
|
import { getTranslation } from "../getTranslation.mjs";
|
|
8
|
-
const translationPlugin = (locale, fallback
|
|
8
|
+
const translationPlugin = (locale, fallback) => ({
|
|
9
9
|
id: "translation-plugin",
|
|
10
10
|
canHandle: (node) => typeof node === "object" && node?.nodeType === NodeType.Translation,
|
|
11
11
|
transform: (node, props, deepTransformNode) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback: boolean = true\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Gender]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<T[NodeType.Gender][keyof T[NodeType.Gender]], S>\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Gender,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Gender]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeType.Gender, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string | number>) => DeepTransformContent<I, S>\n : (data: Record<string, string | number>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n nested: true;\n // file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":"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","names":["node","deepTransformNode","children"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/interpreter/getContent/plugins.ts"],"sourcesContent":["import type { Locales, LocalesValues } from '@intlayer/config/client';\nimport type {\n ConditionContent,\n EnumerationContent,\n FileContent,\n Gender,\n GenderContent,\n InsertionContent,\n NestedContent,\n TranslationContent,\n} from '../../transpiler';\nimport { type DictionaryKeys, type KeyPath, NodeType } from '../../types/index';\nimport { getCondition } from '../getCondition';\nimport { getEnumeration } from '../getEnumeration';\nimport { getGender } from '../getGender';\nimport { getInsertion } from '../getInsertion';\nimport { type GetNestingResult, getNesting } from '../getNesting';\nimport { getTranslation } from '../getTranslation';\n\n/** ---------------------------------------------\n * PLUGIN DEFINITION\n * --------------------------------------------- */\n\n/**\n * A plugin/transformer that can optionally transform a node during a single DFS pass.\n * - `canHandle` decides if the node is transformable by this plugin.\n * - `transform` returns the transformed node (and does not recurse further).\n *\n * > `transformFn` is a function that can be used to deeply transform inside the plugin.\n */\nexport type Plugins = {\n id: string;\n canHandle: (node: any) => boolean;\n transform: (\n node: any,\n props: NodeProps,\n transformFn: (node: any, props: NodeProps) => any\n ) => any;\n};\n\n/** ---------------------------------------------\n * TRANSLATION PLUGIN\n * --------------------------------------------- */\n\nexport type TranslationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Translation]: object;\n}\n ? DeepTransformContent<\n T[NodeType.Translation][keyof T[NodeType.Translation]],\n S\n >\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const translationPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'translation-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Translation]);\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n return getTranslation(result, locale, fallback);\n },\n});\n\n/** ---------------------------------------------\n * ENUMERATION PLUGIN\n * --------------------------------------------- */\n\nexport type EnumerationCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Enumeration]: object;\n}\n ? (\n quantity: number\n ) => DeepTransformContent<\n T[NodeType.Enumeration][keyof T[NodeType.Enumeration]],\n S\n >\n : never;\n\n/** Enumeration plugin. Replaces node with a function that takes quantity => string. */\nexport const enumerationPlugin: Plugins = {\n id: 'enumeration-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Enumeration,\n transform: (node: EnumerationContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Enumeration]);\n\n for (const key in result) {\n const child = result[key as unknown as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Enumeration, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (quantity: number) => getEnumeration(result, quantity);\n },\n};\n\n/** ---------------------------------------------\n * CONDITION PLUGIN\n * --------------------------------------------- */\n\nexport type ConditionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Condition]: object;\n}\n ? (\n value: boolean\n ) => DeepTransformContent<\n T[NodeType.Condition][keyof T[NodeType.Condition]],\n S\n >\n : never;\n\n/** Condition plugin. Replaces node with a function that takes boolean => string. */\nexport const conditionPlugin: Plugins = {\n id: 'condition-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Condition,\n transform: (node: ConditionContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Condition]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Condition, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: boolean) => getCondition(result, value);\n },\n};\n\n/** ---------------------------------------------\n * GENDER PLUGIN\n * --------------------------------------------- */\n\nexport type GenderCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Gender]: object;\n}\n ? (\n value: Gender\n ) => DeepTransformContent<T[NodeType.Gender][keyof T[NodeType.Gender]], S>\n : never;\n\n/** Gender plugin. Replaces node with a function that takes gender => string. */\nexport const genderPlugin: Plugins = {\n id: 'gender-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Gender,\n transform: (node: GenderContent, props, deepTransformNode) => {\n const result = structuredClone(node[NodeType.Gender]);\n\n for (const key in result) {\n const child = result[key as keyof typeof result];\n const childProps = {\n ...props,\n children: child,\n keyPath: [...props.keyPath, { type: NodeType.Gender, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n child,\n childProps\n );\n }\n\n return (value: Gender) => getGender(result, value);\n },\n};\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Insertion]: infer I;\n fields?: infer U;\n}\n ? U extends readonly string[]\n ? (data: Record<U[number], string | number>) => DeepTransformContent<I, S>\n : (data: Record<string, string | number>) => DeepTransformContent<I, S>\n : never;\n\nexport const insertionPlugin: Plugins = {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Insertion,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeType.Insertion,\n },\n ];\n\n const children = node[NodeType.Insertion];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, subProps, deepTransformNode) => {\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }) => {\n const children = getInsertion(transformedResult, values);\n\n return deepTransformNode(children, {\n ...subProps,\n plugins: props.plugins,\n children,\n });\n };\n },\n };\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n },\n};\n\n/** ---------------------------------------------\n * NESTED PLUGIN\n * --------------------------------------------- */\n\nexport type NestedCond<T, S> = T extends {\n nodeType: NodeType | string;\n [NodeType.Nested]: infer U;\n}\n ? U extends {\n dictionaryKey: infer K extends DictionaryKeys;\n path?: infer P;\n }\n ? GetNestingResult<K, P, S>\n : never\n : never;\n\n/** Nested plugin. Replaces node with the result of `getNesting`. */\nexport const nestedPlugin: Plugins = {\n id: 'nested-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Nested,\n transform: (node: NestedContent, props) =>\n getNesting(node.nested.dictionaryKey, node.nested.path, props),\n};\n\n// /** ---------------------------------------------\n// * FILE PLUGIN\n// * --------------------------------------------- */\n\nexport type FileCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeType.File]: string;\n content?: string;\n}\n ? string\n : never;\n\n/** File plugin. Replaces node with the result of `getNesting`. */\nexport const filePlugin: Plugins = {\n id: 'file-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.File,\n transform: (node: FileContent, props, deepTransform) =>\n deepTransform(node.content, {\n ...props,\n children: node.content,\n }),\n};\n\n/**\n * PLUGIN RESULT\n */\n\n/**\n * Interface that defines the properties of a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface NodeProps {\n dictionaryKey: string;\n keyPath: KeyPath[];\n plugins?: Plugins[];\n locale?: Locales;\n dictionaryPath?: string;\n children?: any;\n}\n\n/**\n * Interface that defines the plugins that can be used to transform a node.\n * This interface can be augmented in other packages, such as `react-intlayer`.\n */\nexport interface IInterpreterPlugin<T, S> {\n translation: TranslationCond<T, S>;\n insertion: InsertionCond<T, S>;\n enumeration: EnumerationCond<T, S>;\n condition: ConditionCond<T, S>;\n nested: NestedCond<T, S>;\n // file: FileCond<T>;\n}\n\n/**\n * Allow to avoid overwriting import from `intlayer` package when `IInterpreterPlugin<T>` interface is augmented in another package, such as `react-intlayer`.\n */\nexport type IInterpreterPluginState = {\n translation: true;\n enumeration: true;\n condition: true;\n insertion: true;\n nested: true;\n // file: true;\n};\n\n/**\n * Utility type to check if a plugin can be applied to a node.\n */\ntype CheckApplyPlugin<T, K extends keyof IInterpreterPlugin<T, S>, S> =\n // Test if the key is a key of S.\n K extends keyof S\n ? // Test if the key of S is true. Then the plugin can be applied.\n S[K] extends true\n ? // Test if the key of S exist\n IInterpreterPlugin<T, S>[K] extends never\n ? never\n : // Test if the plugin condition is true (if it's not, the plugin is skipped for this node)\n IInterpreterPlugin<T, S>[K]\n : never\n : never;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\ntype Traverse<T, S> =\n // Turn any read-only array into a plain mutable array\n T extends ReadonlyArray<infer U>\n ? Array<DeepTransformContent<U, S>>\n : T extends object\n ? { [K in keyof T]: DeepTransformContent<T[K], S> }\n : T;\n\n/**\n * Traverse recursively through an object or array, applying each plugin as needed.\n */\nexport type DeepTransformContent<T, S = IInterpreterPluginState> =\n // Check if there is a plugin for T:\n CheckApplyPlugin<T, keyof IInterpreterPlugin<T, S>, S> extends never\n ? // No plugin was found, so try to transform T recursively:\n Traverse<T, S>\n : // A plugin was found – use the plugin’s transformation.\n IInterpreterPlugin<T, S>[keyof IInterpreterPlugin<T, S>];\n"],"mappings":"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","names":["node","deepTransformNode","children"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Dictionary, DictionaryKeys } from '../types';\nimport type { DeepTransformContent, Plugins } from './getContent/plugins';\nimport { getDictionary } from './getDictionary';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const dictionary = dictionaries[key as T];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key as string} not found`, dictionaries);\n }\n\n return getDictionary(\n dictionary as Dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":"AAMA,OAAO,kBAAkB;AAKzB,SAAS,qBAAqB;AAEvB,MAAM,cAAc,CACzB,KACA,QACA,YACG;AACH,QAAM,aAAa,aAAa,GAAQ;AAExC,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAa,cAAc,YAAY;AAAA,EACvE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\n// @ts-ignore intlayer declared for module augmentation\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport type { Dictionary, DictionaryKeys } from '../types';\nimport type { DeepTransformContent, Plugins } from './getContent/plugins';\nimport { getDictionary } from './getDictionary';\n\nexport const getIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: L,\n plugins?: Plugins[]\n) => {\n const dictionary = dictionaries[key as T];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key as string} not found`, dictionaries);\n }\n\n return getDictionary(\n dictionary as Dictionary,\n locale,\n plugins\n ) as any as DeepTransformContent<\n IntlayerDictionaryTypesConnector[T]['content']\n >;\n};\n"],"mappings":"AAMA,OAAO,kBAAkB;AAKzB,SAAS,qBAAqB;AAEvB,MAAM,cAAc,CACzB,KACA,QACA,YACG;AACH,QAAM,aAAa,aAAa,GAAQ;AAExC,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAa,cAAc,YAAY;AAAA,EACvE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAGF;","names":[]}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { defaultLocale } = configuration?.internationalization;
|
|
4
|
-
let result = languageContent[locale ?? defaultLocale];
|
|
1
|
+
const getTranslation = (languageContent, locale, fallback) => {
|
|
2
|
+
let result = languageContent[locale ?? fallback];
|
|
5
3
|
if (fallback && !result) {
|
|
6
|
-
result = languageContent[
|
|
4
|
+
result = languageContent[fallback];
|
|
7
5
|
}
|
|
8
6
|
return result;
|
|
9
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/interpreter/getTranslation.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config/client';\nimport { LanguageContent } from '../types';\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 * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\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 getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: LocalesValues,\n fallback?: LocalesValues\n): Content => {\n let result =\n languageContent[\n (locale ?? fallback) as unknown as keyof typeof languageContent\n ];\n\n if (fallback && !result) {\n result =\n languageContent[fallback as unknown as keyof typeof languageContent];\n }\n\n return result as unknown as Content;\n};\n"],"mappings":"AAwBO,MAAM,iBAAiB,CAC5B,iBACA,QACA,aACY;AACZ,MAAI,SACF,gBACG,UAAU,QACb;AAEF,MAAI,YAAY,CAAC,QAAQ;AACvB,aACE,gBAAgB,QAAmD;AAAA,EACvE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import {\n type TypedNodeModel,\n formatNodeType,\n NodeType,\n} from '../../types/index';\n\ntype
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/enumeration/enumeration.ts"],"sourcesContent":["import {\n type TypedNodeModel,\n formatNodeType,\n NodeType,\n} from '../../types/index';\n\ntype Positive = number | `${number}`;\ntype Negative = `-${number}`;\ntype Numbers = Positive | Negative;\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 EnumerationContentState<Content> = Partial<\n Record<EnterFormat, Content>\n> & {\n fallback?: Content;\n};\n\nexport type EnumerationContent<Content = unknown> = TypedNodeModel<\n NodeType.Enumeration,\n EnumerationContentState<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 * 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?: EnumerationContentState<Content>) =>\n formatNodeType(NodeType.Enumeration, content);\n\nexport { enumeration as enu };\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAmDP,MAAM,cAAc,CAAU,YAC5B,eAAe,SAAS,aAAa,OAAO;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAppLogger } from "@intlayer/config";
|
|
1
|
+
import { colorizePath, getAppLogger } from "@intlayer/config";
|
|
2
2
|
import configuration from "@intlayer/config/built";
|
|
3
3
|
import { existsSync, readFileSync } from "fs";
|
|
4
4
|
import { relative, resolve } from "path";
|
|
@@ -27,7 +27,10 @@ const file = (path) => {
|
|
|
27
27
|
if (existsSync(filePath)) {
|
|
28
28
|
content = readFileSync(filePath, "utf8");
|
|
29
29
|
} else {
|
|
30
|
-
appLogger(
|
|
30
|
+
appLogger(
|
|
31
|
+
`File not found: ${colorizePath(relative(configuration.content.baseDir, filePath))}`,
|
|
32
|
+
{ level: "warn" }
|
|
33
|
+
);
|
|
31
34
|
content = `File not found`;
|
|
32
35
|
}
|
|
33
36
|
return formatNodeType(NodeType.File, path, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { existsSync, readFileSync } from 'fs';\nimport { relative, resolve } from 'path';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger(configuration);\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(`File not found: ${filePath}
|
|
1
|
+
{"version":3,"sources":["../../../../src/transpiler/file/file.ts"],"sourcesContent":["import { colorizePath, getAppLogger } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { existsSync, readFileSync } from 'fs';\nimport { relative, resolve } from 'path';\nimport {\n formatNodeType,\n NodeType,\n type TypedNodeModel,\n} from '../../types/index';\n\nexport type FileContentConstructor<T extends Record<string, any> = {}> =\n TypedNodeModel<NodeType.File, string, T>;\n\nexport type FileContent = FileContentConstructor<{\n content: string;\n fixedPath?: string;\n}>;\n\ndeclare const intlayer_file_path: string; // Injected by esbuild to track the file content\ndeclare const intlayer_file_dir: string; // Injected by esbuild to track the file path\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow identify the usage of an external resource.\n *\n * Usage:\n *\n * ```ts\n * file('/path/to/file.md') // absolute path\n *\n * // or\n *\n * file('path/to/file.md') // relative path\n * ```\n */\nexport const file = (path: string): FileContent => {\n const callerDir = intlayer_file_dir ?? process.cwd();\n\n const isAbsolutePath = path.startsWith('/');\n const isRelativePath = path.startsWith('./') || path.startsWith('../');\n const appLogger = getAppLogger(configuration);\n\n let filePath: string;\n if (isAbsolutePath) {\n appLogger(\n `Using absolute path for file is not recommended. Use relative paths instead. Path: ${path}, imported from: ${intlayer_file_path}`,\n { level: 'warn' }\n );\n filePath = path;\n } else if (isRelativePath) {\n filePath = resolve(callerDir, path);\n } else {\n filePath = resolve(process.cwd(), path);\n }\n\n let content: string;\n\n if (existsSync(filePath)) {\n content = readFileSync(filePath, 'utf8');\n } else {\n appLogger(\n `File not found: ${colorizePath(relative(configuration.content.baseDir, filePath))}`,\n { level: 'warn' }\n );\n\n content = `File not found`;\n }\n\n return formatNodeType(NodeType.File, path, {\n content,\n fixedPath: relative(process.cwd(), filePath),\n });\n};\n"],"mappings":"AAAA,SAAS,cAAc,oBAAoB;AAC3C,OAAO,mBAAmB;AAC1B,SAAS,YAAY,oBAAoB;AACzC,SAAS,UAAU,eAAe;AAClC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AA4BA,MAAM,OAAO,CAAC,SAA8B;AACjD,QAAM,YAAY,qBAAqB,QAAQ,IAAI;AAEnD,QAAM,iBAAiB,KAAK,WAAW,GAAG;AAC1C,QAAM,iBAAiB,KAAK,WAAW,IAAI,KAAK,KAAK,WAAW,KAAK;AACrE,QAAM,YAAY,aAAa,aAAa;AAE5C,MAAI;AACJ,MAAI,gBAAgB;AAClB;AAAA,MACE,sFAAsF,IAAI,oBAAoB,kBAAkB;AAAA,MAChI,EAAE,OAAO,OAAO;AAAA,IAClB;AACA,eAAW;AAAA,EACb,WAAW,gBAAgB;AACzB,eAAW,QAAQ,WAAW,IAAI;AAAA,EACpC,OAAO;AACL,eAAW,QAAQ,QAAQ,IAAI,GAAG,IAAI;AAAA,EACxC;AAEA,MAAI;AAEJ,MAAI,WAAW,QAAQ,GAAG;AACxB,cAAU,aAAa,UAAU,MAAM;AAAA,EACzC,OAAO;AACL;AAAA,MACE,mBAAmB,aAAa,SAAS,cAAc,QAAQ,SAAS,QAAQ,CAAC,CAAC;AAAA,MAClF,EAAE,OAAO,OAAO;AAAA,IAClB;AAEA,cAAU;AAAA,EACZ;AAEA,SAAO,eAAe,SAAS,MAAM,MAAM;AAAA,IACzC;AAAA,IACA,WAAW,SAAS,QAAQ,IAAI,GAAG,QAAQ;AAAA,EAC7C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IConfigLocales,
|
|
3
|
+
IntlayerDictionaryTypesConnector,
|
|
4
|
+
LanguageContent,
|
|
5
|
+
LocalesValues
|
|
6
|
+
} from "intlayer";
|
|
7
|
+
export {
|
|
8
|
+
IConfigLocales,
|
|
9
|
+
IntlayerDictionaryTypesConnector,
|
|
10
|
+
LanguageContent,
|
|
11
|
+
LocalesValues
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=intlayer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/intlayer.ts"],"sourcesContent":["// @ts-nocheck\n/**\n * Reexport the intlayer module with the module augmentation because of typescript error\n */\n\nexport {\n IConfigLocales,\n IntlayerDictionaryTypesConnector,\n LanguageContent,\n LocalesValues,\n} from 'intlayer';\n"],"mappings":"AAKA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
|
package/dist/esm/utils/intl.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Locales } from "@intlayer/config/client";
|
|
2
2
|
const cacheKey = (locales, options) => JSON.stringify([locales, options]);
|
|
3
3
|
const createCachedConstructor = (Ctor) => {
|
|
4
4
|
const cache = /* @__PURE__ */ new Map();
|
|
@@ -11,10 +11,7 @@ const createCachedConstructor = (Ctor) => {
|
|
|
11
11
|
}
|
|
12
12
|
return locales;
|
|
13
13
|
}
|
|
14
|
-
const key = cacheKey(
|
|
15
|
-
locales ?? configuration.internationalization.defaultLocale,
|
|
16
|
-
options
|
|
17
|
-
);
|
|
14
|
+
const key = cacheKey(locales ?? Locales.ENGLISH, options);
|
|
18
15
|
let instance = cache.get(key);
|
|
19
16
|
if (!instance) {
|
|
20
17
|
instance = new Ctor(locales, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { LocalesValues } from '@intlayer/config
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/config/client';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (...args: any) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? new (locales?: LocalesValues, options?: Options) => Instance\n : T extends new (locales: any) => infer Instance\n ? new (locales?: LocalesValues) => Instance\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// Generic cache key – JSON.stringify is fine because locale strings are short\n// and option objects are small and deterministic.\nconst cacheKey = (locales: LocalesValues, options: unknown) =>\n JSON.stringify([locales, options]);\n\n// Generic wrapper for any `new Intl.*()` constructor.\n// Returns a constructable function (usable with or without `new`) that\n// pulls instances from a Map cache when possible.\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n const cache = new Map<string, InstanceType<T>>();\n\n function Wrapped(locales?: LocalesValues, options?: any) {\n // Special case – guard older runtimes missing DisplayNames.\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n if (process.env.NODE_ENV === 'development') {\n console.warn(\n `Intl.DisplayNames is not supported; falling back to raw locale (${locales}). ` +\n `Consider adding a polyfill as https://formatjs.io/docs/polyfills/intl-displaynames/`\n );\n }\n return locales as any;\n }\n\n const key = cacheKey(locales ?? Locales.ENGLISH, options);\n let instance: InstanceType<T> | undefined = cache.get(key);\n\n if (!instance) {\n instance = new Ctor(locales as never, options as never);\n cache.set(key, instance as InstanceType<T>);\n }\n\n return instance as InstanceType<T>;\n }\n\n // Ensure it behaves like a constructor when used with `new`.\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n// Factory that turns the global `Intl` into a cached clone.\nexport const createCachedIntl = (): WrappedIntl =>\n new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap *only* constructor functions (safest heuristic: they start with a capital letter).\n return typeof value === 'function' && /^[A-Z]/.test(String(prop))\n ? createCachedConstructor(value)\n : value;\n },\n }) as unknown as WrappedIntl;\n\n// Singleton – import this in application code if you just want shared caches.\nconst CachedIntl = createCachedIntl();\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\n\nexport { CachedIntl as Intl };\n"],"mappings":"AAwBA,SAAS,eAAmC;AA8B5C,MAAM,WAAW,CAAC,SAAwB,YACxC,KAAK,UAAU,CAAC,SAAS,OAAO,CAAC;AAKnC,MAAM,0BAA0B,CAC9B,SACG;AACH,QAAM,QAAQ,oBAAI,IAA6B;AAE/C,WAAS,QAAQ,SAAyB,SAAe;AAEvD,QACE,KAAK,SAAS,kBACd,OAAQ,MAAc,iBAAiB,YACvC;AACA,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ;AAAA,UACN,mEAAmE,OAAO;AAAA,QAE5E;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,MAAM,SAAS,WAAW,QAAQ,SAAS,OAAO;AACxD,QAAI,WAAwC,MAAM,IAAI,GAAG;AAEzD,QAAI,CAAC,UAAU;AACb,iBAAW,IAAI,KAAK,SAAkB,OAAgB;AACtD,YAAM,IAAI,KAAK,QAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,EACT;AAGA,EAAC,QAAgB,YAAa,KAAa;AAE3C,SAAO;AACT;AAGO,MAAM,mBAAmB,MAC9B,IAAI,MAAM,MAA0B;AAAA,EAClC,KAAK,CAAC,QAAQ,MAAM,aAAa;AAC/B,UAAM,QAAQ,QAAQ,IAAI,QAAQ,MAAM,QAAQ;AAGhD,WAAO,OAAO,UAAU,cAAc,SAAS,KAAK,OAAO,IAAI,CAAC,IAC5D,wBAAwB,KAAK,IAC7B;AAAA,EACN;AACF,CAAC;AAGH,MAAM,aAAa,iBAAiB;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Locales, LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { type DeepTransformContent, type NodeProps, type Plugins } from '../interpreter/getContent/plugins';
|
|
3
|
+
import { type ContentNode } from '../types';
|
|
4
|
+
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
5
|
+
export declare const filterTranslationsOnlyPlugin: (locale: LocalesValues, fallback?: LocalesValues) => Plugins;
|
|
6
|
+
/**
|
|
7
|
+
* Return the content of a node with only the translation plugin.
|
|
8
|
+
*
|
|
9
|
+
* @param node The node to transform.
|
|
10
|
+
* @param locale The locale to use if your transformers need it (e.g. for translations).
|
|
11
|
+
*/
|
|
12
|
+
export declare const getFilterTranslationsOnlyContent: <T extends ContentNode, L extends LocalesValues = Locales>(node: T, locale: L, nodeProps: NodeProps, fallback?: LocalesValues) => DeepTransformContent<T>;
|
|
13
|
+
//# sourceMappingURL=getFilterTranslationsOnlyContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilterTranslationsOnlyContent.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getFilterTranslationsOnlyContent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGtE,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,OAAO,EACb,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAqB/D,wFAAwF;AACxF,eAAO,MAAM,4BAA4B,GACvC,QAAQ,aAAa,EACrB,WAAW,aAAa,KACvB,OAyED,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAC3C,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,aAAa,GAAG,OAAO,EAEjC,MAAM,CAAC,EACP,QAAQ,CAA0D,EAClE,WAAW,SAAS,EACpB,WAAW,aAAa,KAUlB,oBAAoB,CAAC,CAAC,CAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilterTranslationsOnlyContent.test.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getFilterTranslationsOnlyContent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { type NodeProps } from '../interpreter';
|
|
3
|
+
import { type ContentNode } from '../types';
|
|
4
|
+
export declare const getFilteredLocalesContent: (node: ContentNode, locale: LocalesValues | LocalesValues[], nodeProps: NodeProps) => any;
|
|
5
|
+
//# sourceMappingURL=getFilteredLocalesContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFilteredLocalesContent.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getFilteredLocalesContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,KAAK,SAAS,EAGf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,UAAU,CAAC;AA8BtD,eAAO,MAAM,yBAAyB,GACpC,MAAM,WAAW,EACjB,QAAQ,aAAa,GAAG,aAAa,EAAE,EACvC,WAAW,SAAS,QAWrB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locales, LocalesValues } from '@intlayer/config/client';
|
|
2
|
-
import type
|
|
3
|
-
import
|
|
2
|
+
import { type DeepTransformContent, type NodeProps } from '../interpreter/getContent/plugins';
|
|
3
|
+
import type { ContentNode } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Transforms a node in a single pass, applying each plugin as needed.
|
|
6
6
|
* In comparison to `getContent`, this function will only apply the translation plugin.
|
|
@@ -9,5 +9,5 @@ import { type DeepTransformContent, type NodeProps } from './plugins';
|
|
|
9
9
|
* @param node The node to transform.
|
|
10
10
|
* @param locale The locale to use if your transformers need it (e.g. for translations).
|
|
11
11
|
*/
|
|
12
|
-
export declare const getLocalisedContent: <T extends ContentNode, L extends LocalesValues = Locales>(node: T, locale: L, nodeProps: NodeProps, fallback?:
|
|
12
|
+
export declare const getLocalisedContent: <T extends ContentNode, L extends LocalesValues = Locales>(node: T, locale: L, nodeProps: NodeProps, fallback?: LocalesValues) => DeepTransformContent<T>;
|
|
13
13
|
//# sourceMappingURL=getLocalisedContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLocalisedContent.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getLocalisedContent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,SAAS,EAEf,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAC9B,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,aAAa,GAAG,OAAO,EAEjC,MAAM,CAAC,EACP,QAAQ,CAA0D,EAClE,WAAW,SAAS,EACpB,WAAW,aAAa,KAUlB,oBAAoB,CAAC,CAAC,CAC7B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Locales, LocalesValues } from '@intlayer/config/client';
|
|
2
|
+
import { type NodeProps, type Plugins } from '../interpreter/getContent/plugins';
|
|
3
|
+
import { type ContentNode } from '../types';
|
|
4
|
+
/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
|
|
5
|
+
export declare const checkMissingLocalesPlugin: (locales: Locales[], onMissingLocale: (locale: Locales) => void) => Plugins;
|
|
6
|
+
/**
|
|
7
|
+
* Return the content of a node with only the translation plugin.
|
|
8
|
+
*
|
|
9
|
+
* @param node The node to transform.
|
|
10
|
+
* @param locales The locales to check for missing translations.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getMissingLocalesContent: <T extends ContentNode>(node: T, locales: LocalesValues[], nodeProps: NodeProps) => Locales[];
|
|
13
|
+
//# sourceMappingURL=getMissingLocalesContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMissingLocalesContent.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getMissingLocalesContent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,OAAO,EACb,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAEtD,wFAAwF;AACxF,eAAO,MAAM,yBAAyB,GACpC,SAAS,OAAO,EAAE,EAClB,iBAAiB,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KACzC,OA4BD,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,SAAS,WAAW,EAC5D,MAAM,CAAC,EACP,SAAS,aAAa,EAAgD,EACtE,WAAW,SAAS,KACnB,OAAO,EAgBT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMissingLocalesContent.test.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getMissingLocalesContent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type NodeProps } from '../interpreter';
|
|
2
|
+
import { type ContentNode } from '../types';
|
|
3
|
+
export declare const getReplacedValuesContent: (node: ContentNode, value: string | number | boolean, nodeProps: NodeProps) => any;
|
|
4
|
+
//# sourceMappingURL=getReplacedValuesContent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getReplacedValuesContent.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getReplacedValuesContent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAgC,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAuD1E,eAAO,MAAM,wBAAwB,GACnC,MAAM,WAAW,EACjB,OAAO,MAAM,GAAG,MAAM,GAAG,OAAO,EAChC,WAAW,SAAS,QAcrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getReplacedValuesContent.test.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/getReplacedValuesContent.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/deepTranformPlugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oCAAoC,CAAC;AACnD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNodeChildren.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAA4B,MAAM,UAAU,CAAC;AAEtE,eAAO,MAAM,eAAe,GAAI,SAAS,WAAW,KAAG,
|
|
1
|
+
{"version":3,"file":"getNodeChildren.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getNodeChildren.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAA4B,MAAM,UAAU,CAAC;AAEtE,eAAO,MAAM,eAAe,GAAI,SAAS,WAAW,KAAG,WA2CtD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import unmergedDictionary from '@intlayer/unmerged-dictionaries-entry';
|
|
2
|
+
import { type KeyPath } from '../types';
|
|
3
|
+
export declare const getUnmergedDictionaryByKeyPath: (dictionaryKey: string, keyPath: KeyPath[], dictionariesRecord?: keyof typeof unmergedDictionary) => any;
|
|
4
|
+
//# sourceMappingURL=getUnmergedDictionaryByKeyPath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUnmergedDictionaryByKeyPath.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/getUnmergedDictionaryByKeyPath.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAGxC,eAAO,MAAM,8BAA8B,GACzC,eAAe,MAAM,EACrB,SAAS,OAAO,EAAE,EAClB,qBAAoB,MAAM,OAAO,kBAAuC,QAezE,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from './editDictionaryByKeyPath';
|
|
2
2
|
export * from './getContentNodeByKeyPath';
|
|
3
|
+
export * from './getDefaultNode';
|
|
4
|
+
export * from './getEmptyNode';
|
|
3
5
|
export * from './getNodeChildren';
|
|
6
|
+
export * from './getNodeType';
|
|
7
|
+
export * from './getUnmergedDictionaryByKeyPath';
|
|
4
8
|
export * from './removeContentNodeByKeyPath';
|
|
5
9
|
export * from './renameContentNodeByKeyPath';
|
|
6
|
-
export * from './getNodeType';
|
|
7
10
|
export * from './updateNodeChildren';
|
|
8
|
-
export * from './getDefaultNode';
|
|
9
|
-
export * from './getEmptyNode';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dictionaryManipulator/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC"}
|