@fluid-topics/ft-wc-utils 1.1.102 → 1.1.104
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.
|
@@ -3,8 +3,9 @@ export declare class ParametrizedLabelResolver<T extends ParametrizedLabels = Pa
|
|
|
3
3
|
private defaultLabels;
|
|
4
4
|
private labels;
|
|
5
5
|
constructor(defaultLabels: T, labels: T);
|
|
6
|
-
resolve(key: keyof T, ...args: any[]): string
|
|
6
|
+
resolve(key: keyof T, ...args: any[]): string;
|
|
7
|
+
static replaceParameters(label: string, ...args: any[]): string;
|
|
7
8
|
private resolvePluralKey;
|
|
8
|
-
private formatValue;
|
|
9
|
-
private formatDate;
|
|
9
|
+
private static formatValue;
|
|
10
|
+
private static formatDate;
|
|
10
11
|
}
|
|
@@ -7,7 +7,10 @@ export class ParametrizedLabelResolver {
|
|
|
7
7
|
var _a, _b;
|
|
8
8
|
key = this.resolvePluralKey(key, args);
|
|
9
9
|
let label = (_b = (_a = this.labels[key]) !== null && _a !== void 0 ? _a : this.defaultLabels[key]) !== null && _b !== void 0 ? _b : "";
|
|
10
|
-
|
|
10
|
+
return ParametrizedLabelResolver.replaceParameters(label, ...args);
|
|
11
|
+
}
|
|
12
|
+
static replaceParameters(label, ...args) {
|
|
13
|
+
args.forEach((value, index) => label = label.replace(new RegExp(`\\{${index}([^}]*)\\}`, "g"), (match, modifier) => ParametrizedLabelResolver.formatValue(value, modifier)));
|
|
11
14
|
return label;
|
|
12
15
|
}
|
|
13
16
|
resolvePluralKey(key, args) {
|
|
@@ -21,10 +24,10 @@ export class ParametrizedLabelResolver {
|
|
|
21
24
|
}
|
|
22
25
|
return key;
|
|
23
26
|
}
|
|
24
|
-
formatValue(value, modifier) {
|
|
25
|
-
return value instanceof Date ?
|
|
27
|
+
static formatValue(value, modifier) {
|
|
28
|
+
return value instanceof Date ? ParametrizedLabelResolver.formatDate(value, modifier) : (value !== null && value !== void 0 ? value : "");
|
|
26
29
|
}
|
|
27
|
-
formatDate(value, modifier) {
|
|
30
|
+
static formatDate(value, modifier) {
|
|
28
31
|
const format = (lang) => {
|
|
29
32
|
if (modifier === null || modifier === void 0 ? void 0 : modifier.includes("date")) {
|
|
30
33
|
return value.toLocaleDateString(lang);
|