@digitaldefiance/i18n-lib 1.0.24 → 1.0.25
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/utils.d.ts +3 -3
- package/dist/utils.js +11 -7
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -26,16 +26,16 @@ export declare function isValidTimezone(timezone: string): boolean;
|
|
|
26
26
|
export declare function toStringKey<TStringKey extends string>(...parts: (string)[]): TStringKey;
|
|
27
27
|
/**
|
|
28
28
|
* Converts an enum value to a string key by joining parts with underscores and appending the enum value.
|
|
29
|
-
* @param enumObj - The enum object
|
|
30
29
|
* @param value - The enum value
|
|
31
30
|
* @param parts - Additional parts to join
|
|
32
31
|
* @returns The constructed string key
|
|
33
32
|
*/
|
|
34
|
-
export declare function toStringKeyFromEnum<TStringKey extends string
|
|
33
|
+
export declare function toStringKeyFromEnum<TStringKey extends string>(value: string, ...parts: string[]): TStringKey;
|
|
35
34
|
/**
|
|
36
35
|
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
37
36
|
* @param enumObj - The enum object
|
|
38
37
|
* @param prefixes - Prefixes to prepend to each string key
|
|
38
|
+
* @param templateKeys - Optional set of enum values that should have 'Template' suffix for template processing
|
|
39
39
|
* @returns The constructed reason map
|
|
40
40
|
*/
|
|
41
|
-
export declare function buildReasonMap<
|
|
41
|
+
export declare function buildReasonMap<TEnum extends Record<string, string>, TStringKey extends string>(enumObj: TEnum, prefixes?: string[], templateKeys?: Set<TEnum[keyof TEnum]>): Record<TEnum[keyof TEnum], TStringKey>;
|
package/dist/utils.js
CHANGED
|
@@ -63,23 +63,27 @@ function toStringKey(...parts) {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Converts an enum value to a string key by joining parts with underscores and appending the enum value.
|
|
66
|
-
* @param enumObj - The enum object
|
|
67
66
|
* @param value - The enum value
|
|
68
67
|
* @param parts - Additional parts to join
|
|
69
68
|
* @returns The constructed string key
|
|
70
69
|
*/
|
|
71
70
|
function toStringKeyFromEnum(value, ...parts) {
|
|
72
|
-
|
|
71
|
+
const allParts = [...parts, value];
|
|
72
|
+
return allParts.join('_');
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
76
76
|
* @param enumObj - The enum object
|
|
77
77
|
* @param prefixes - Prefixes to prepend to each string key
|
|
78
|
+
* @param templateKeys - Optional set of enum values that should have 'Template' suffix for template processing
|
|
78
79
|
* @returns The constructed reason map
|
|
79
80
|
*/
|
|
80
|
-
function buildReasonMap(enumObj,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
function buildReasonMap(enumObj, prefixes = [], templateKeys) {
|
|
82
|
+
const map = {};
|
|
83
|
+
Object.values(enumObj).forEach(value => {
|
|
84
|
+
const baseKey = [...prefixes, value].join('_');
|
|
85
|
+
const finalKey = templateKeys?.has(value) ? baseKey + 'Template' : baseKey;
|
|
86
|
+
map[value] = finalKey;
|
|
87
|
+
});
|
|
88
|
+
return map;
|
|
85
89
|
}
|