@digitaldefiance/i18n-lib 1.0.19 → 1.0.21
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 +8 -1
- package/dist/utils.js +14 -1
- package/package.json +1 -1
package/dist/utils.d.ts
CHANGED
|
@@ -31,4 +31,11 @@ export declare function toStringKey<TStringKey extends string>(...parts: (string
|
|
|
31
31
|
* @param parts - Additional parts to join
|
|
32
32
|
* @returns The constructed string key
|
|
33
33
|
*/
|
|
34
|
-
export declare function toStringKeyFromEnum<TStringKey extends string, TEnum>(
|
|
34
|
+
export declare function toStringKeyFromEnum<TStringKey extends string, TEnum extends string>(value: TEnum[keyof TEnum], ...parts: (string)[]): TStringKey;
|
|
35
|
+
/**
|
|
36
|
+
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
37
|
+
* @param enumObj - The enum object
|
|
38
|
+
* @param prefixes - Prefixes to prepend to each string key
|
|
39
|
+
* @returns The constructed reason map
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildReasonMap<TStringKey extends string, TEnum extends Record<string, string>>(enumObj: TEnum, ...prefixes: string[]): Record<string, TStringKey>;
|
package/dist/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.isTemplate = isTemplate;
|
|
|
8
8
|
exports.isValidTimezone = isValidTimezone;
|
|
9
9
|
exports.toStringKey = toStringKey;
|
|
10
10
|
exports.toStringKeyFromEnum = toStringKeyFromEnum;
|
|
11
|
+
exports.buildReasonMap = buildReasonMap;
|
|
11
12
|
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
12
13
|
/**
|
|
13
14
|
* Replaces variables in a string with their corresponding values from vars or constants.
|
|
@@ -67,6 +68,18 @@ function toStringKey(...parts) {
|
|
|
67
68
|
* @param parts - Additional parts to join
|
|
68
69
|
* @returns The constructed string key
|
|
69
70
|
*/
|
|
70
|
-
function toStringKeyFromEnum(
|
|
71
|
+
function toStringKeyFromEnum(value, ...parts) {
|
|
71
72
|
return parts.join('_') + '_' + String(value);
|
|
72
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Builds a reason map from an enum object, mapping each enum value to a string key.
|
|
76
|
+
* @param enumObj - The enum object
|
|
77
|
+
* @param prefixes - Prefixes to prepend to each string key
|
|
78
|
+
* @returns The constructed reason map
|
|
79
|
+
*/
|
|
80
|
+
function buildReasonMap(enumObj, ...prefixes) {
|
|
81
|
+
return Object.values(enumObj).reduce((map, value) => {
|
|
82
|
+
map[value] = toStringKeyFromEnum(value, ...prefixes);
|
|
83
|
+
return map;
|
|
84
|
+
}, {});
|
|
85
|
+
}
|