@digitaldefiance/i18n-lib 1.0.20 → 1.0.22

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.
@@ -31,7 +31,7 @@ export declare class I18nEngine<TStringKey extends string, TLanguage extends str
31
31
  /**
32
32
  * Default template processor instance
33
33
  */
34
- readonly t: (key: TStringKey, vars?: Record<string, string | number>, language?: TLanguage) => string;
34
+ readonly t: (str: string, language?: TLanguage, ...otherVars: Record<string, string | number>[]) => string;
35
35
  /**
36
36
  * Creates a new I18nEngine instance
37
37
  * @param config The i18n configuration
package/dist/utils.d.ts CHANGED
@@ -32,3 +32,10 @@ export declare function toStringKey<TStringKey extends string>(...parts: (string
32
32
  * @returns The constructed string key
33
33
  */
34
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.
@@ -70,3 +71,15 @@ function toStringKey(...parts) {
70
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/i18n-lib",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "Generic i18n library with enum translation support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",