@digitaldefiance/i18n-lib 1.2.1 → 1.2.2

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.
@@ -1,41 +0,0 @@
1
- /**
2
- * Replaces variables in a string with their corresponding values from vars or constants.
3
- * @param str - The string containing variables to replace
4
- * @param vars - An object mapping variable names to their replacement values
5
- * @param constants - An object containing constant values for replacement
6
- * @returns The string with variables replaced
7
- */
8
- export declare function replaceVariables(str: string, vars?: Record<string, string | number>, constants?: any): string;
9
- /**
10
- * Checks if a given key indicates a template string.
11
- * @param key - The key to check
12
- * @returns True if the key indicates a template, false otherwise
13
- */
14
- export declare function isTemplate(key: string): boolean;
15
- /**
16
- * Checks if a given timezone string is valid.
17
- * @param timezone - The timezone string to validate
18
- * @returns
19
- */
20
- export declare function isValidTimezone(timezone: string): boolean;
21
- /**
22
- * Converts parts to a single string key, joining with underscores.
23
- * @param parts - The parts to join
24
- * @returns The joined string key
25
- */
26
- export declare function toStringKey<TStringKey extends string>(...parts: (string)[]): TStringKey;
27
- /**
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
- * @param value - The enum value
31
- * @param parts - Additional parts to join
32
- * @returns The constructed string key
33
- */
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/src/utils.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.replaceVariables = replaceVariables;
7
- exports.isTemplate = isTemplate;
8
- exports.isValidTimezone = isValidTimezone;
9
- exports.toStringKey = toStringKey;
10
- exports.toStringKeyFromEnum = toStringKeyFromEnum;
11
- exports.buildReasonMap = buildReasonMap;
12
- const moment_timezone_1 = __importDefault(require("moment-timezone"));
13
- /**
14
- * Replaces variables in a string with their corresponding values from vars or constants.
15
- * @param str - The string containing variables to replace
16
- * @param vars - An object mapping variable names to their replacement values
17
- * @param constants - An object containing constant values for replacement
18
- * @returns The string with variables replaced
19
- */
20
- function replaceVariables(str, vars, constants) {
21
- const variables = str.match(/\{(.+?)\}/g);
22
- if (!variables)
23
- return str;
24
- let result = str;
25
- for (const variable of variables) {
26
- const varName = variable.slice(1, -1);
27
- let replacement = '';
28
- if (vars && varName in vars) {
29
- replacement = String(vars[varName]);
30
- }
31
- else if (constants && varName in constants) {
32
- replacement = String(constants[varName]);
33
- }
34
- if (replacement) {
35
- result = result.replace(variable, replacement);
36
- }
37
- }
38
- return result;
39
- }
40
- /**
41
- * Checks if a given key indicates a template string.
42
- * @param key - The key to check
43
- * @returns True if the key indicates a template, false otherwise
44
- */
45
- function isTemplate(key) {
46
- return key.trim().toLowerCase().endsWith('template');
47
- }
48
- /**
49
- * Checks if a given timezone string is valid.
50
- * @param timezone - The timezone string to validate
51
- * @returns
52
- */
53
- function isValidTimezone(timezone) {
54
- return moment_timezone_1.default.tz.zone(timezone) !== null;
55
- }
56
- /**
57
- * Converts parts to a single string key, joining with underscores.
58
- * @param parts - The parts to join
59
- * @returns The joined string key
60
- */
61
- function toStringKey(...parts) {
62
- return parts.join('_');
63
- }
64
- /**
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
- * @param value - The enum value
68
- * @param parts - Additional parts to join
69
- * @returns The constructed string key
70
- */
71
- function toStringKeyFromEnum(value, ...parts) {
72
- return parts.join('_') + '_' + String(value);
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
- }