@webiny/i18n 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9
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/I18n.d.ts +2 -2
- package/I18n.js +158 -425
- package/I18n.js.map +1 -1
- package/README.md +7 -13
- package/extractor/extract.js +24 -57
- package/extractor/extract.js.map +1 -1
- package/extractor/index.js +32 -60
- package/extractor/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +12 -34
- package/index.js.map +1 -1
- package/modifiers/countModifier.d.ts +1 -1
- package/modifiers/countModifier.js +17 -41
- package/modifiers/countModifier.js.map +1 -1
- package/modifiers/dateModifier.d.ts +1 -1
- package/modifiers/dateModifier.js +9 -19
- package/modifiers/dateModifier.js.map +1 -1
- package/modifiers/dateTimeModifier.d.ts +1 -1
- package/modifiers/dateTimeModifier.js +9 -19
- package/modifiers/dateTimeModifier.js.map +1 -1
- package/modifiers/genderModifier.d.ts +1 -1
- package/modifiers/genderModifier.js +9 -19
- package/modifiers/genderModifier.js.map +1 -1
- package/modifiers/ifModifier.d.ts +1 -1
- package/modifiers/ifModifier.js +9 -19
- package/modifiers/ifModifier.js.map +1 -1
- package/modifiers/index.d.ts +1 -1
- package/modifiers/index.js +23 -31
- package/modifiers/index.js.map +1 -1
- package/modifiers/numberModifier.d.ts +1 -1
- package/modifiers/numberModifier.js +9 -19
- package/modifiers/numberModifier.js.map +1 -1
- package/modifiers/pluralModifier.d.ts +1 -1
- package/modifiers/pluralModifier.js +17 -40
- package/modifiers/pluralModifier.js.map +1 -1
- package/modifiers/priceModifier.d.ts +1 -1
- package/modifiers/priceModifier.js +9 -19
- package/modifiers/priceModifier.js.map +1 -1
- package/modifiers/timeModifier.d.ts +1 -1
- package/modifiers/timeModifier.js +9 -19
- package/modifiers/timeModifier.js.map +1 -1
- package/package.json +23 -29
- package/processors/default.d.ts +1 -1
- package/processors/default.js +34 -64
- package/processors/default.js.map +1 -1
- package/types.d.ts +3 -3
- package/types.js +0 -5
- package/types.js.map +0 -1
package/modifiers/ifModifier.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name: "if",
|
|
11
|
-
|
|
12
|
-
execute(value, parameters) {
|
|
13
|
-
return value === parameters[0] ? parameters[1] : parameters[2] || "";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
exports.default = _default;
|
|
1
|
+
const ifModifier = ()=>({
|
|
2
|
+
name: "if",
|
|
3
|
+
execute (value, parameters) {
|
|
4
|
+
return value === parameters[0] ? parameters[1] : parameters[2] || "";
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
export default ifModifier;
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=ifModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"modifiers/ifModifier.js","sources":["../../src/modifiers/ifModifier.ts"],"sourcesContent":["import type { Modifier } from \"~/types.js\";\n\nexport default (): Modifier => {\n return {\n name: \"if\",\n execute(value: string, parameters: Array<string>) {\n return value === parameters[0] ? parameters[1] : parameters[2] || \"\";\n }\n };\n};\n"],"names":["value","parameters"],"mappings":"AAEA,mBAAgB,IACL;QACH,MAAM;QACN,SAAQA,KAAa,EAAEC,UAAyB;YAC5C,OAAOD,UAAUC,UAAU,CAAC,EAAE,GAAGA,UAAU,CAAC,EAAE,GAAGA,UAAU,CAAC,EAAE,IAAI;QACtE;IACJ"}
|
package/modifiers/index.d.ts
CHANGED
package/modifiers/index.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var _numberModifier = _interopRequireDefault(require("./numberModifier"));
|
|
25
|
-
|
|
26
|
-
var _priceModifier = _interopRequireDefault(require("./priceModifier"));
|
|
27
|
-
|
|
28
|
-
// Built-in modifiers
|
|
29
|
-
var _default = options => [(0, _countModifier.default)(), (0, _genderModifier.default)(), (0, _ifModifier.default)(), (0, _pluralModifier.default)(), (0, _dateModifier.default)(options), (0, _dateTimeModifier.default)(options), (0, _timeModifier.default)(options), (0, _numberModifier.default)(options), (0, _priceModifier.default)(options)];
|
|
30
|
-
|
|
31
|
-
exports.default = _default;
|
|
1
|
+
import countModifier from "./countModifier.js";
|
|
2
|
+
import genderModifier from "./genderModifier.js";
|
|
3
|
+
import ifModifier from "./ifModifier.js";
|
|
4
|
+
import pluralModifier from "./pluralModifier.js";
|
|
5
|
+
import dateModifier from "./dateModifier.js";
|
|
6
|
+
import dateTimeModifier from "./dateTimeModifier.js";
|
|
7
|
+
import timeModifier from "./timeModifier.js";
|
|
8
|
+
import numberModifier from "./numberModifier.js";
|
|
9
|
+
import priceModifier from "./priceModifier.js";
|
|
10
|
+
const modifiers = (options)=>[
|
|
11
|
+
countModifier(),
|
|
12
|
+
genderModifier(),
|
|
13
|
+
ifModifier(),
|
|
14
|
+
pluralModifier(),
|
|
15
|
+
dateModifier(options),
|
|
16
|
+
dateTimeModifier(options),
|
|
17
|
+
timeModifier(options),
|
|
18
|
+
numberModifier(options),
|
|
19
|
+
priceModifier(options)
|
|
20
|
+
];
|
|
21
|
+
export default modifiers;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
package/modifiers/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"modifiers/index.js","sources":["../../src/modifiers/index.ts"],"sourcesContent":["// Built-in modifiers\nimport countModifiers from \"./countModifier.js\";\nimport genderModifier from \"./genderModifier.js\";\nimport ifModifier from \"./ifModifier.js\";\nimport pluralModifier from \"./pluralModifier.js\";\nimport dateModifier from \"./dateModifier.js\";\nimport dateTimeModifier from \"./dateTimeModifier.js\";\nimport timeModifier from \"./timeModifier.js\";\nimport numberModifier from \"./numberModifier.js\";\nimport priceModifier from \"./priceModifier.js\";\nimport type { Modifier, ModifierOptions } from \"~/types.js\";\n\nexport default (options: ModifierOptions): Modifier[] => [\n countModifiers(),\n genderModifier(),\n ifModifier(),\n pluralModifier(),\n dateModifier(options),\n dateTimeModifier(options),\n timeModifier(options),\n numberModifier(options),\n priceModifier(options)\n];\n"],"names":["options","countModifiers","genderModifier","ifModifier","pluralModifier","dateModifier","dateTimeModifier","timeModifier","numberModifier","priceModifier"],"mappings":";;;;;;;;;AAYA,kBAAgB,CAAAA,UAAyC;QACrDC;QACAC;QACAC;QACAC;QACAC,aAAaL;QACbM,iBAAiBN;QACjBO,aAAaP;QACbQ,eAAeR;QACfS,cAAcT;KAClB"}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}) => ({
|
|
11
|
-
name: "number",
|
|
12
|
-
|
|
13
|
-
execute(value) {
|
|
14
|
-
return i18n.number(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
exports.default = _default;
|
|
1
|
+
const numberModifier = ({ i18n })=>({
|
|
2
|
+
name: "number",
|
|
3
|
+
execute (value) {
|
|
4
|
+
return i18n.number(value);
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
export default numberModifier;
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=numberModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"modifiers/numberModifier.js","sources":["../../src/modifiers/numberModifier.ts"],"sourcesContent":["import type { Modifier, ModifierOptions } from \"~/types.js\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"number\",\n execute(value: string) {\n return i18n.number(value);\n }\n});\n"],"names":["i18n","value"],"mappings":"AAEA,uBAAgB,GAAEA,IAAI,EAAmB,GAAgB;QACrD,MAAM;QACN,SAAQC,KAAa;YACjB,OAAOD,KAAK,MAAM,CAACC;QACvB;IACJ"}
|
|
@@ -1,42 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const current = parameters[i];
|
|
16
|
-
|
|
17
|
-
if (current === "default") {
|
|
18
|
-
return parameters[i + 1];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const numbers = current.split("-"); // If we are dealing with a numbers range, then let's check if we are in it.
|
|
22
|
-
|
|
23
|
-
if (numbers.length === 2) {
|
|
24
|
-
if (value >= numbers[0] && value <= numbers[1]) {
|
|
25
|
-
return parameters[i + 1];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (String(value) === numbers[0]) {
|
|
32
|
-
return parameters[i + 1];
|
|
1
|
+
const pluralModifier = ()=>({
|
|
2
|
+
name: "plural",
|
|
3
|
+
execute (value, parameters) {
|
|
4
|
+
for(let i = 0; i < parameters.length; i += 2){
|
|
5
|
+
const current = parameters[i];
|
|
6
|
+
if ("default" === current) return parameters[i + 1];
|
|
7
|
+
const numbers = current.split("-");
|
|
8
|
+
if (2 === numbers.length) {
|
|
9
|
+
if (value >= numbers[0] && value <= numbers[1]) return parameters[i + 1];
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (String(value) === numbers[0]) return parameters[i + 1];
|
|
13
|
+
}
|
|
14
|
+
return "";
|
|
33
15
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
};
|
|
16
|
+
});
|
|
17
|
+
export default pluralModifier;
|
|
41
18
|
|
|
42
|
-
|
|
19
|
+
//# sourceMappingURL=pluralModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"modifiers/pluralModifier.js","sources":["../../src/modifiers/pluralModifier.ts"],"sourcesContent":["import type { Modifier } from \"~/types.js\";\n\nexport default (): Modifier => {\n return {\n name: \"plural\",\n execute(value: string, parameters: Array<string>) {\n // Numbers can be single number or ranges.\n for (let i = 0; i < parameters.length; i = i + 2) {\n const current = parameters[i];\n if (current === \"default\") {\n return parameters[i + 1];\n }\n\n const numbers = current.split(\"-\");\n\n // If we are dealing with a numbers range, then let's check if we are in it.\n if (numbers.length === 2) {\n if (value >= numbers[0] && value <= numbers[1]) {\n return parameters[i + 1];\n }\n continue;\n }\n\n if (String(value) === numbers[0]) {\n return parameters[i + 1];\n }\n }\n\n return \"\";\n }\n };\n};\n"],"names":["value","parameters","i","current","numbers","String"],"mappings":"AAEA,uBAAgB,IACL;QACH,MAAM;QACN,SAAQA,KAAa,EAAEC,UAAyB;YAE5C,IAAK,IAAIC,IAAI,GAAGA,IAAID,WAAW,MAAM,EAAEC,KAAQ,EAAG;gBAC9C,MAAMC,UAAUF,UAAU,CAACC,EAAE;gBAC7B,IAAIC,AAAY,cAAZA,SACA,OAAOF,UAAU,CAACC,IAAI,EAAE;gBAG5B,MAAME,UAAUD,QAAQ,KAAK,CAAC;gBAG9B,IAAIC,AAAmB,MAAnBA,QAAQ,MAAM,EAAQ;oBACtB,IAAIJ,SAASI,OAAO,CAAC,EAAE,IAAIJ,SAASI,OAAO,CAAC,EAAE,EAC1C,OAAOH,UAAU,CAACC,IAAI,EAAE;oBAE5B;gBACJ;gBAEA,IAAIG,OAAOL,WAAWI,OAAO,CAAC,EAAE,EAC5B,OAAOH,UAAU,CAACC,IAAI,EAAE;YAEhC;YAEA,OAAO;QACX;IACJ"}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}) => ({
|
|
11
|
-
name: "price",
|
|
12
|
-
|
|
13
|
-
execute(value) {
|
|
14
|
-
return i18n.price(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
exports.default = _default;
|
|
1
|
+
const priceModifier = ({ i18n })=>({
|
|
2
|
+
name: "price",
|
|
3
|
+
execute (value) {
|
|
4
|
+
return i18n.price(value);
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
export default priceModifier;
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=priceModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"modifiers/priceModifier.js","sources":["../../src/modifiers/priceModifier.ts"],"sourcesContent":["import type { Modifier, ModifierOptions } from \"~/types.js\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"price\",\n execute(value: string) {\n return i18n.price(value);\n }\n});\n"],"names":["i18n","value"],"mappings":"AAEA,sBAAgB,GAAEA,IAAI,EAAmB,GAAgB;QACrD,MAAM;QACN,SAAQC,KAAa;YACjB,OAAOD,KAAK,KAAK,CAACC;QACtB;IACJ"}
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}) => ({
|
|
11
|
-
name: "time",
|
|
12
|
-
|
|
13
|
-
execute(value) {
|
|
14
|
-
return i18n.time(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
exports.default = _default;
|
|
1
|
+
const timeModifier = ({ i18n })=>({
|
|
2
|
+
name: "time",
|
|
3
|
+
execute (value) {
|
|
4
|
+
return i18n.time(value);
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
export default timeModifier;
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=timeModifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"modifiers/timeModifier.js","sources":["../../src/modifiers/timeModifier.ts"],"sourcesContent":["import type { Modifier, ModifierOptions } from \"~/types.js\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"time\",\n execute(value: string) {\n return i18n.time(value);\n }\n});\n"],"names":["i18n","value"],"mappings":"AAEA,qBAAgB,GAAEA,IAAI,EAAmB,GAAgB;QACrD,MAAM;QACN,SAAQC,KAAa;YACjB,OAAOD,KAAK,IAAI,CAACC;QACrB;IACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/i18n",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.7be00a75a9",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
5
9
|
"repository": {
|
|
6
10
|
"type": "git",
|
|
7
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -13,39 +17,29 @@
|
|
|
13
17
|
],
|
|
14
18
|
"license": "MIT",
|
|
15
19
|
"dependencies": {
|
|
16
|
-
"@babel/runtime": "7.19.0",
|
|
17
20
|
"accounting": "0.4.1",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
21
|
+
"fast-glob": "3.3.3",
|
|
22
|
+
"fecha": "4.2.3",
|
|
23
|
+
"lodash": "4.18.1",
|
|
24
|
+
"ohash": "2.0.11",
|
|
25
|
+
"yargs": "18.0.0"
|
|
22
26
|
},
|
|
23
27
|
"peerDependencies": {
|
|
24
|
-
"react": "
|
|
28
|
+
"react": "18.3.1"
|
|
25
29
|
},
|
|
26
30
|
"devDependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"@types/lodash": "^4.14.190",
|
|
34
|
-
"@webiny/cli": "^0.0.0-unstable.78f581c1d2",
|
|
35
|
-
"@webiny/project-utils": "^0.0.0-unstable.78f581c1d2",
|
|
36
|
-
"babel-plugin-lodash": "^3.3.4",
|
|
37
|
-
"glob": "^7.1.2",
|
|
38
|
-
"rimraf": "^3.0.2",
|
|
39
|
-
"ttypescript": "^1.5.13",
|
|
40
|
-
"typescript": "4.7.4"
|
|
31
|
+
"@types/accounting": "0.4.5",
|
|
32
|
+
"@types/lodash": "4.17.24",
|
|
33
|
+
"@webiny/build-tools": "0.0.0-unstable.7be00a75a9",
|
|
34
|
+
"rimraf": "6.1.3",
|
|
35
|
+
"typescript": "6.0.3",
|
|
36
|
+
"vitest": "4.1.7"
|
|
41
37
|
},
|
|
42
38
|
"publishConfig": {
|
|
43
|
-
"access": "public"
|
|
44
|
-
"directory": "dist"
|
|
45
|
-
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"build": "yarn webiny run build",
|
|
48
|
-
"watch": "yarn webiny run watch"
|
|
39
|
+
"access": "public"
|
|
49
40
|
},
|
|
50
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
|
|
42
|
+
"webiny": {
|
|
43
|
+
"publishFrom": "dist"
|
|
44
|
+
}
|
|
51
45
|
}
|
package/processors/default.d.ts
CHANGED
package/processors/default.js
CHANGED
|
@@ -1,69 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!values[variable]) {
|
|
21
|
-
return `{${variable}}`;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const output = {
|
|
25
|
-
value: values[variable]
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
if (modifier) {
|
|
29
|
-
const parameters = modifier.split(":");
|
|
30
|
-
const name = parameters.shift();
|
|
31
|
-
|
|
32
|
-
if (!name) {
|
|
33
|
-
return output.value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (modifiers[name]) {
|
|
37
|
-
const modifier = modifiers[name];
|
|
38
|
-
output.value = modifier.execute(output.value, parameters);
|
|
1
|
+
import trim from "lodash/trim.js";
|
|
2
|
+
const processTextPart = (part, values, modifiers)=>{
|
|
3
|
+
if (false === part.startsWith("{")) return part;
|
|
4
|
+
const parts = trim(part, "{}").split("|");
|
|
5
|
+
const [variable, modifier] = parts;
|
|
6
|
+
const keys = Object.keys(values);
|
|
7
|
+
if (!keys.includes(variable)) return `{${variable}}`;
|
|
8
|
+
const output = {
|
|
9
|
+
value: values[variable]
|
|
10
|
+
};
|
|
11
|
+
if (modifier) {
|
|
12
|
+
const parameters = modifier.split(":");
|
|
13
|
+
const name = parameters.shift();
|
|
14
|
+
if (!name) return output.value;
|
|
15
|
+
if (modifiers[name]) {
|
|
16
|
+
const modifier = modifiers[name];
|
|
17
|
+
output.value = modifier.execute(output.value, parameters);
|
|
18
|
+
}
|
|
39
19
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return output.value;
|
|
20
|
+
return output.value;
|
|
43
21
|
};
|
|
44
|
-
|
|
45
22
|
const processor = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
23
|
+
name: "default",
|
|
24
|
+
canExecute (data) {
|
|
25
|
+
for(const key in data.values){
|
|
26
|
+
const value = data.values[key];
|
|
27
|
+
if ("string" != typeof value && "number" != typeof value && null !== value && !(value instanceof Date)) return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
execute (data) {
|
|
32
|
+
const parts = data.translation.split(/({.*?})/);
|
|
33
|
+
return parts.reduce((carry, part)=>carry + processTextPart(part, data.values, data.i18n.modifiers), "");
|
|
57
34
|
}
|
|
58
|
-
|
|
59
|
-
return true;
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
execute(data) {
|
|
63
|
-
const parts = data.translation.split(/({.*?})/);
|
|
64
|
-
return parts.reduce((carry, part) => carry + processTextPart(part, data.values, data.i18n.modifiers), "");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
35
|
};
|
|
68
|
-
|
|
69
|
-
|
|
36
|
+
const processors_default = processor;
|
|
37
|
+
export default processors_default;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"processors/default.js","sources":["../../src/processors/default.ts"],"sourcesContent":["import lodashTrim from \"lodash/trim.js\";\nimport type { Modifier, Processor } from \"~/types.js\";\n\nconst processTextPart = (\n part: string,\n values: Record<string, any>,\n modifiers: Record<string, Modifier>\n): string => {\n if (part.startsWith(\"{\") === false) {\n return part;\n }\n\n const parts = lodashTrim(part, \"{}\").split(\"|\");\n\n const [variable, modifier] = parts;\n const keys = Object.keys(values);\n\n if (!keys.includes(variable)) {\n return `{${variable}}`;\n }\n\n const output = {\n value: values[variable]\n };\n\n if (modifier) {\n const parameters: string[] = modifier.split(\":\");\n const name = parameters.shift();\n if (!name) {\n return output.value;\n }\n if (modifiers[name]) {\n const modifier = modifiers[name];\n output.value = modifier.execute(output.value, parameters);\n }\n }\n\n return output.value;\n};\n\nconst processor: Processor = {\n name: \"default\",\n canExecute(data) {\n for (const key in data.values) {\n const value = data.values[key];\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n value === null ||\n value instanceof Date\n ) {\n continue;\n }\n return false;\n }\n\n return true;\n },\n execute(data) {\n const parts = data.translation.split(/({.*?})/);\n return parts.reduce(\n (carry, part) => carry + processTextPart(part, data.values, data.i18n.modifiers),\n \"\"\n );\n }\n};\n\nexport default processor;\n"],"names":["processTextPart","part","values","modifiers","parts","lodashTrim","variable","modifier","keys","Object","output","parameters","name","processor","data","key","value","Date","carry"],"mappings":";AAGA,MAAMA,kBAAkB,CACpBC,MACAC,QACAC;IAEA,IAAIF,AAAyB,UAAzBA,KAAK,UAAU,CAAC,MAChB,OAAOA;IAGX,MAAMG,QAAQC,KAAWJ,MAAM,MAAM,KAAK,CAAC;IAE3C,MAAM,CAACK,UAAUC,SAAS,GAAGH;IAC7B,MAAMI,OAAOC,OAAO,IAAI,CAACP;IAEzB,IAAI,CAACM,KAAK,QAAQ,CAACF,WACf,OAAO,CAAC,CAAC,EAAEA,SAAS,CAAC,CAAC;IAG1B,MAAMI,SAAS;QACX,OAAOR,MAAM,CAACI,SAAS;IAC3B;IAEA,IAAIC,UAAU;QACV,MAAMI,aAAuBJ,SAAS,KAAK,CAAC;QAC5C,MAAMK,OAAOD,WAAW,KAAK;QAC7B,IAAI,CAACC,MACD,OAAOF,OAAO,KAAK;QAEvB,IAAIP,SAAS,CAACS,KAAK,EAAE;YACjB,MAAML,WAAWJ,SAAS,CAACS,KAAK;YAChCF,OAAO,KAAK,GAAGH,SAAS,OAAO,CAACG,OAAO,KAAK,EAAEC;QAClD;IACJ;IAEA,OAAOD,OAAO,KAAK;AACvB;AAEA,MAAMG,YAAuB;IACzB,MAAM;IACN,YAAWC,IAAI;QACX,IAAK,MAAMC,OAAOD,KAAK,MAAM,CAAE;YAC3B,MAAME,QAAQF,KAAK,MAAM,CAACC,IAAI;YAC9B,IACI,AAAiB,YAAjB,OAAOC,SACP,AAAiB,YAAjB,OAAOA,SACPA,AAAU,SAAVA,UACAA,CAAAA,iBAAiBC,IAAG,GAIxB,OAAO;QACX;QAEA,OAAO;IACX;IACA,SAAQH,IAAI;QACR,MAAMV,QAAQU,KAAK,WAAW,CAAC,KAAK,CAAC;QACrC,OAAOV,MAAM,MAAM,CACf,CAACc,OAAOjB,OAASiB,QAAQlB,gBAAgBC,MAAMa,KAAK,MAAM,EAAEA,KAAK,IAAI,CAAC,SAAS,GAC/E;IAER;AACJ;AAEA,2BAAeD"}
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import I18N from "./I18n";
|
|
2
|
-
import { ReactElement } from "react";
|
|
1
|
+
import type I18N from "./I18n.js";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
3
|
export interface I18NDataValues {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
}
|
|
@@ -20,7 +20,7 @@ export interface Modifier {
|
|
|
20
20
|
name: string;
|
|
21
21
|
execute: (...args: any[]) => string;
|
|
22
22
|
}
|
|
23
|
-
export
|
|
23
|
+
export type ProcessorResult = string | ReactElement;
|
|
24
24
|
/**
|
|
25
25
|
* @description I18N Processor - used for outputting text.
|
|
26
26
|
*/
|
package/types.js
CHANGED
package/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import I18N from \"./I18n\";\nimport { ReactElement } from \"react\";\n\nexport interface I18NDataValues {\n [key: string]: any;\n}\nexport interface I18NData {\n translation: string;\n base: string;\n namespace: string;\n values: I18NDataValues;\n i18n: I18N;\n}\n\nexport interface ModifierOptions {\n i18n: I18N;\n}\n/**\n * @description I18N Modifier - used for modifying text dynamically.\n */\nexport interface Modifier {\n name: string;\n execute: (...args: any[]) => string;\n}\n\nexport type ProcessorResult = string | ReactElement;\n/**\n * @description I18N Processor - used for outputting text.\n */\nexport interface Processor {\n name: string;\n canExecute: (data: I18NData) => boolean;\n execute: (data: I18NData) => ProcessorResult;\n}\n\nexport interface NumberFormat {\n decimal: string;\n thousand: string;\n precision: number;\n}\n\nexport interface PriceFormat {\n symbol: string;\n format: string;\n decimal: string;\n thousand: string;\n precision: number;\n}\n\nexport interface Formats {\n date: string;\n time: string;\n datetime: string;\n price: PriceFormat;\n number: NumberFormat;\n}\n\nexport interface Translator {\n (base: any): any;\n}\n\nexport interface Translations {\n [key: string]: string;\n}\n"],"mappings":""}
|