reslib 1.0.0

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.
Files changed (200) hide show
  1. package/README.md +298 -0
  2. package/build/auth/index.d.ts +2034 -0
  3. package/build/auth/index.js +5 -0
  4. package/build/auth/types.d.ts +465 -0
  5. package/build/auth/types.js +1 -0
  6. package/build/countries/countries.d.ts +1454 -0
  7. package/build/countries/countries.js +1 -0
  8. package/build/countries/index.d.ts +159 -0
  9. package/build/countries/index.js +5 -0
  10. package/build/countries/types.d.ts +65 -0
  11. package/build/countries/types.js +1 -0
  12. package/build/currency/currencies.d.ts +8 -0
  13. package/build/currency/currencies.js +1 -0
  14. package/build/currency/index.d.ts +51 -0
  15. package/build/currency/index.js +5 -0
  16. package/build/currency/session.d.ts +23 -0
  17. package/build/currency/session.js +5 -0
  18. package/build/currency/types.d.ts +1039 -0
  19. package/build/currency/types.js +1 -0
  20. package/build/currency/utils.d.ts +25 -0
  21. package/build/currency/utils.js +1 -0
  22. package/build/i18n/index.d.ts +640 -0
  23. package/build/i18n/index.js +5 -0
  24. package/build/inputFormatter/index.d.ts +396 -0
  25. package/build/inputFormatter/index.js +5 -0
  26. package/build/inputFormatter/types.d.ts +544 -0
  27. package/build/inputFormatter/types.js +1 -0
  28. package/build/logger/index.d.ts +235 -0
  29. package/build/logger/index.js +5 -0
  30. package/build/observable/index.d.ts +329 -0
  31. package/build/observable/index.js +1 -0
  32. package/build/platform/index.d.ts +32 -0
  33. package/build/platform/index.js +1 -0
  34. package/build/resources/ResourcePaginationHelper.d.ts +537 -0
  35. package/build/resources/ResourcePaginationHelper.js +2 -0
  36. package/build/resources/decorators/create.decorator.d.ts +20 -0
  37. package/build/resources/decorators/create.decorator.js +1 -0
  38. package/build/resources/decorators/index.d.ts +41 -0
  39. package/build/resources/decorators/index.js +1 -0
  40. package/build/resources/fields/index.d.ts +33 -0
  41. package/build/resources/fields/index.js +1 -0
  42. package/build/resources/filters.d.ts +62 -0
  43. package/build/resources/filters.js +1 -0
  44. package/build/resources/index.d.ts +854 -0
  45. package/build/resources/index.js +6 -0
  46. package/build/resources/types/filters.d.ts +508 -0
  47. package/build/resources/types/filters.js +1 -0
  48. package/build/resources/types/index.d.ts +4138 -0
  49. package/build/resources/types/index.js +1 -0
  50. package/build/session/index.d.ts +1474 -0
  51. package/build/session/index.js +1 -0
  52. package/build/translations/auth.en.d.ts +3 -0
  53. package/build/translations/auth.en.js +1 -0
  54. package/build/translations/countries.en.d.ts +6 -0
  55. package/build/translations/countries.en.js +1 -0
  56. package/build/translations/currencies.en.d.ts +5 -0
  57. package/build/translations/currencies.en.js +1 -0
  58. package/build/translations/date.en.d.ts +19 -0
  59. package/build/translations/date.en.js +1 -0
  60. package/build/translations/index.d.ts +1583 -0
  61. package/build/translations/index.js +5 -0
  62. package/build/translations/resources.en.d.ts +6 -0
  63. package/build/translations/resources.en.js +1 -0
  64. package/build/translations/validator.en.d.ts +104 -0
  65. package/build/translations/validator.en.js +5 -0
  66. package/build/types/date.d.ts +44 -0
  67. package/build/types/date.js +1 -0
  68. package/build/types/dictionary.d.ts +29 -0
  69. package/build/types/dictionary.js +1 -0
  70. package/build/types/i18n.d.ts +121 -0
  71. package/build/types/i18n.js +1 -0
  72. package/build/types/index.d.ts +145 -0
  73. package/build/types/index.js +1 -0
  74. package/build/utils/areEquals.d.ts +19 -0
  75. package/build/utils/areEquals.js +1 -0
  76. package/build/utils/date/dateHelper.d.ts +371 -0
  77. package/build/utils/date/dateHelper.js +5 -0
  78. package/build/utils/date/index.d.ts +212 -0
  79. package/build/utils/date/index.js +5 -0
  80. package/build/utils/date/isDateObj.d.ts +14 -0
  81. package/build/utils/date/isDateObj.js +1 -0
  82. package/build/utils/debounce.d.ts +52 -0
  83. package/build/utils/debounce.js +1 -0
  84. package/build/utils/defaultArray.d.ts +18 -0
  85. package/build/utils/defaultArray.js +1 -0
  86. package/build/utils/defaultBool.d.ts +14 -0
  87. package/build/utils/defaultBool.js +1 -0
  88. package/build/utils/defaultStr.d.ts +17 -0
  89. package/build/utils/defaultStr.js +1 -0
  90. package/build/utils/defaultVal.d.ts +18 -0
  91. package/build/utils/defaultVal.js +1 -0
  92. package/build/utils/dom/index.d.ts +65 -0
  93. package/build/utils/dom/index.js +1 -0
  94. package/build/utils/dom/isDOMElement.d.ts +11 -0
  95. package/build/utils/dom/isDOMElement.js +1 -0
  96. package/build/utils/file/index.d.ts +26 -0
  97. package/build/utils/file/index.js +1 -0
  98. package/build/utils/global.d.ts +53 -0
  99. package/build/utils/global.js +1 -0
  100. package/build/utils/image.d.ts +56 -0
  101. package/build/utils/image.js +1 -0
  102. package/build/utils/index.d.ts +39 -0
  103. package/build/utils/index.js +6 -0
  104. package/build/utils/interpolate.d.ts +105 -0
  105. package/build/utils/interpolate.js +1 -0
  106. package/build/utils/isEmail.d.ts +57 -0
  107. package/build/utils/isEmail.js +1 -0
  108. package/build/utils/isEmpty.d.ts +18 -0
  109. package/build/utils/isEmpty.js +1 -0
  110. package/build/utils/isNonNullString.d.ts +17 -0
  111. package/build/utils/isNonNullString.js +1 -0
  112. package/build/utils/isNullable.d.ts +7 -0
  113. package/build/utils/isNullable.js +1 -0
  114. package/build/utils/isNumber.d.ts +36 -0
  115. package/build/utils/isNumber.js +1 -0
  116. package/build/utils/isPrimitive.d.ts +16 -0
  117. package/build/utils/isPrimitive.js +1 -0
  118. package/build/utils/isPromise.d.ts +14 -0
  119. package/build/utils/isPromise.js +1 -0
  120. package/build/utils/isRegex.d.ts +15 -0
  121. package/build/utils/isRegex.js +1 -0
  122. package/build/utils/isTime.d.ts +18 -0
  123. package/build/utils/isTime.js +1 -0
  124. package/build/utils/json.d.ts +224 -0
  125. package/build/utils/json.js +1 -0
  126. package/build/utils/numbers.d.ts +148 -0
  127. package/build/utils/numbers.js +5 -0
  128. package/build/utils/object.d.ts +567 -0
  129. package/build/utils/object.js +1 -0
  130. package/build/utils/sort.d.ts +67 -0
  131. package/build/utils/sort.js +1 -0
  132. package/build/utils/string.d.ts +165 -0
  133. package/build/utils/string.js +1 -0
  134. package/build/utils/stringify.d.ts +23 -0
  135. package/build/utils/stringify.js +1 -0
  136. package/build/utils/uniqid.d.ts +18 -0
  137. package/build/utils/uniqid.js +1 -0
  138. package/build/utils/uri/index.d.ts +333 -0
  139. package/build/utils/uri/index.js +2 -0
  140. package/build/validator/index.d.ts +4 -0
  141. package/build/validator/index.js +6 -0
  142. package/build/validator/rules/array.d.ts +848 -0
  143. package/build/validator/rules/array.js +5 -0
  144. package/build/validator/rules/boolean.d.ts +87 -0
  145. package/build/validator/rules/boolean.js +5 -0
  146. package/build/validator/rules/date.d.ts +551 -0
  147. package/build/validator/rules/date.js +5 -0
  148. package/build/validator/rules/default.d.ts +367 -0
  149. package/build/validator/rules/default.js +5 -0
  150. package/build/validator/rules/enum.d.ts +155 -0
  151. package/build/validator/rules/enum.js +5 -0
  152. package/build/validator/rules/file.d.ts +356 -0
  153. package/build/validator/rules/file.js +5 -0
  154. package/build/validator/rules/format.d.ts +2825 -0
  155. package/build/validator/rules/format.js +6 -0
  156. package/build/validator/rules/index.d.ts +16 -0
  157. package/build/validator/rules/index.js +6 -0
  158. package/build/validator/rules/multiRules.d.ts +475 -0
  159. package/build/validator/rules/multiRules.js +5 -0
  160. package/build/validator/rules/numeric.d.ts +1135 -0
  161. package/build/validator/rules/numeric.js +5 -0
  162. package/build/validator/rules/string.d.ts +504 -0
  163. package/build/validator/rules/string.js +5 -0
  164. package/build/validator/rules/target.d.ts +137 -0
  165. package/build/validator/rules/target.js +5 -0
  166. package/build/validator/rules/utils.d.ts +1 -0
  167. package/build/validator/rules/utils.js +1 -0
  168. package/build/validator/rulesMarkers.d.ts +11 -0
  169. package/build/validator/rulesMarkers.js +1 -0
  170. package/build/validator/types.d.ts +2906 -0
  171. package/build/validator/types.js +1 -0
  172. package/build/validator/validator.d.ts +3692 -0
  173. package/build/validator/validator.js +5 -0
  174. package/lib/cjs/auth.js +1 -0
  175. package/lib/cjs/countries.js +1 -0
  176. package/lib/cjs/currency.js +1 -0
  177. package/lib/cjs/i18n.js +1 -0
  178. package/lib/cjs/inputFormatter.js +1 -0
  179. package/lib/cjs/logger.js +1 -0
  180. package/lib/cjs/observable.js +1 -0
  181. package/lib/cjs/platform.js +1 -0
  182. package/lib/cjs/resources.js +1 -0
  183. package/lib/cjs/session.js +1 -0
  184. package/lib/cjs/types.js +1 -0
  185. package/lib/cjs/utils.js +1 -0
  186. package/lib/cjs/validator.js +1 -0
  187. package/lib/esm/auth.mjs +1 -0
  188. package/lib/esm/countries.mjs +1 -0
  189. package/lib/esm/currency.mjs +1 -0
  190. package/lib/esm/i18n.mjs +1 -0
  191. package/lib/esm/inputFormatter.mjs +1 -0
  192. package/lib/esm/logger.mjs +1 -0
  193. package/lib/esm/observable.mjs +1 -0
  194. package/lib/esm/platform.mjs +1 -0
  195. package/lib/esm/resources.mjs +1 -0
  196. package/lib/esm/session.mjs +1 -0
  197. package/lib/esm/types.mjs +1 -0
  198. package/lib/esm/utils.mjs +1 -0
  199. package/lib/esm/validator.mjs +1 -0
  200. package/package.json +244 -0
@@ -0,0 +1 @@
1
+ 'use strict';
@@ -0,0 +1,25 @@
1
+ import { Currency } from './types';
2
+ /**
3
+ *
4
+ * Checks if the provided object is a valid currency object.
5
+ * A valid currency object must be a non-null object with the following properties:
6
+ * - `name`: A string representing the name of the currency.
7
+ * - `symbol`: A string representing the symbol of the currency.
8
+ *
9
+ * @param {any} obj - The object to be validated as a currency.
10
+ * @returns {boolean} Returns `true` if the object is a valid currency, otherwise `false`.
11
+ *
12
+ * @example
13
+ * const usd = { name: "US Dollar", symbol: "$" };
14
+ * console.log(isCurrency(usd)); // Output: true
15
+ *
16
+ * const invalidCurrency = { name: "Invalid Currency" };
17
+ * console.log(isCurrency(invalidCurrency)); // Output: false
18
+ *
19
+ * const notAnObject = "Not an object";
20
+ * console.log(isCurrency(notAnObject)); // Output: false
21
+ *
22
+ * const arrayInput = ["$"];
23
+ * console.log(isCurrency(arrayInput)); // Output: false
24
+ */
25
+ export declare const isCurrency: (obj: any) => obj is Currency;
@@ -0,0 +1 @@
1
+ 'use strict';var y=r=>r&&typeof r=="object"&&!Array.isArray(r)&&r.name&&typeof r.name=="string"&&r.symbol&&typeof r.symbol=="string";exports.isCurrency=y;
@@ -0,0 +1,640 @@
1
+ import { Observable, ObservableCallback } from '../observable';
2
+ import { Dict, I18n as I18nJs, I18nOptions, Scope, TranslateOptions } from 'i18n-js';
3
+ import { LocaleSpecification } from 'moment';
4
+ import 'reflect-metadata';
5
+ import { I18nEvent, I18nTranslation } from '../types/i18n';
6
+ import { ClassConstructor, Dictionary } from '../types/index';
7
+ /**
8
+ * A decorator to attach metadata to properties or methods for translation.
9
+ * @param key The translation key in the translations.
10
+ * @returns A property and method decorator.
11
+ * @example
12
+ * ```ts
13
+ * // Class with translations using the decorator
14
+ class MyComponent {
15
+ @Translate("greeting")
16
+ public greeting: string;
17
+
18
+ @Translate("nested.example")
19
+ public nestedExample: string;
20
+
21
+ @Translate("farewell")
22
+ public sayGoodbye(): string {
23
+ return "";
24
+ }
25
+ }
26
+ * ```
27
+ */
28
+ export declare function Translate(key: string): PropertyDecorator & MethodDecorator;
29
+ /**
30
+ * The I18n class extends the i18n-js library to provide internationalization (i18n)
31
+ * functionality with observable capabilities. It manages translations, allows for
32
+ * dynamic loading of language dictionaries, and supports event-driven architecture
33
+ * through observable patterns.
34
+ *
35
+ * @extends I18nJs
36
+ * @implements Observable<I18nEvent>
37
+ *
38
+ * @example
39
+ * // Example usage of the I18n class
40
+ * const i18nInstance = I18n.getInstance();
41
+ * i18nInstance.registerTranslations({
42
+ * en: {
43
+ * greeting: "Hello, %{name}!",
44
+ * farewell: "Goodbye!",
45
+ * },
46
+ * });
47
+ * console.log(i18nInstance.translate("greeting", { name: "John" })); // Outputs: Hello, John!
48
+ * @see https://www.npmjs.com/package/i18n-js?activeTab=readme for more information on i18n-js library.
49
+ */
50
+ export declare class I18n extends I18nJs implements Observable<I18nEvent> {
51
+ /**
52
+ * Custom instanceof check. When consumers import `I18n` from built packages or
53
+ * across module boundaries, class identity can differ. Using Symbol.hasInstance
54
+ * allows `instanceof I18n` to succeed if the object has the required i18n API
55
+ * shape (duck typing). This preserves `instanceof` checks externally while
56
+ * keeping the current exported API intact.
57
+ */
58
+ static [Symbol.hasInstance](obj: any): obj is I18n;
59
+ /**
60
+ * Type guard to check if an object is an instance of I18n.
61
+ * Uses duck typing to verify the object has the required i18n methods,
62
+ * allowing for cross-realm compatibility when instanceof checks fail.
63
+ * @param obj The object to check.
64
+ * @returns True if the object is an I18n instance, false otherwise.
65
+ */
66
+ static isI18nInstance(obj: any): obj is I18n;
67
+ /**
68
+ * Translates the given scope with the provided options.
69
+ * If the scope is a string and the options include pluralization, the method will pluralize the translation.
70
+ * Otherwise, it will call the parent `translate` method.
71
+ * @param scope The translation scope.
72
+ * @param options The translation options, including pluralization.
73
+ * @returns The translated string or the type specified in the generic parameter.
74
+ * @example
75
+ * // Register translations for the "en" locale.
76
+ * i18n.registerTranslations({
77
+ * en: {
78
+ * greeting: {
79
+ * one: "Hello, %{name}!",
80
+ * other: "Hello, %{name}s!",
81
+ * zero: "Hello, %{name}s!"
82
+ * },
83
+ * farewell: "Goodbye!"
84
+ * }
85
+ * });
86
+ *
87
+ * // Translate the "greeting" scope with pluralization.
88
+ * i18n.translate("greeting", { count: 1 }); // "Hello, John!"
89
+ * i18n.translate("greeting", { count: 2 }); // "Hello, Johns!"
90
+ * i18n.translate("greeting", { count: 0 }); // "Hello, Johns!"
91
+ *
92
+ * // Translate the "farewell" scope.
93
+ * i18n.translate("farewell"); // "Goodbye!"
94
+ */
95
+ translate<T = string>(scope: Scope, options?: TranslateOptions): string | T;
96
+ /***
97
+ * Translates the keys of the given target class.
98
+ * @param target The target class.
99
+ * @param options The translation options.
100
+ * @returns The translated keys.
101
+ */
102
+ translateTarget<T extends ClassConstructor>(target: T, options?: TranslateOptions): Record<keyof T, string>;
103
+ /**
104
+ * Translates an object containing translation keys as values.
105
+ * This method takes an object where each property value is expected to be a translation key,
106
+ * and returns a new object with the same structure but with translated values.
107
+ *
108
+ * @template T - The type of the input object, extending Record<string, string>
109
+ * @param object - The object containing translation keys as values to be translated
110
+ * @param {TranslateOptions} options - additional options to pass to the i18n.translate function
111
+ * @returns A new object with the same keys but translated values
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * // Register translations first
116
+ * i18n.registerTranslations({
117
+ * en: {
118
+ * 'user.name': 'Name',
119
+ * 'user.email': 'Email Address',
120
+ * 'user.phone': 'Phone Number',
121
+ * 'actions.save': 'Save',
122
+ * 'actions.cancel': 'Cancel'
123
+ * },
124
+ * fr: {
125
+ * 'user.name': 'Nom',
126
+ * 'user.email': 'Adresse Email',
127
+ * 'user.phone': 'Numéro de Téléphone',
128
+ * 'actions.save': 'Enregistrer',
129
+ * 'actions.cancel': 'Annuler'
130
+ * }
131
+ * });
132
+ *
133
+ * // Define an object with translation keys
134
+ * const formLabels = {
135
+ * name: 'user.name',
136
+ * email: 'user.email',
137
+ * phone: 'user.phone'
138
+ * };
139
+ *
140
+ * // Translate the object
141
+ * const translatedLabels = i18n.translateObject(formLabels);
142
+ * console.log(translatedLabels);
143
+ * // Output (for 'en' locale): { name: 'Name', email: 'Email Address', phone: 'Phone Number' }
144
+ * // Output (for 'fr' locale): { name: 'Nom', email: 'Adresse Email', phone: 'Numéro de Téléphone' }
145
+ *
146
+ * // Can also be used with button configurations
147
+ * const buttonConfig = {
148
+ * saveButton: 'actions.save',
149
+ * cancelButton: 'actions.cancel'
150
+ * };
151
+ * const translatedButtons = i18n.translateObject(buttonConfig);
152
+ * // Output (for 'en' locale): { saveButton: 'Save', cancelButton: 'Cancel' }
153
+ * ```
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * // Advanced usage with form validation messages
158
+ * const validationMessages = {
159
+ * required: 'validation.required',
160
+ * email: 'validation.email.invalid',
161
+ * minLength: 'validation.minLength',
162
+ * maxLength: 'validation.maxLength'
163
+ * };
164
+ *
165
+ * // Assuming you have registered validation translations
166
+ * const translatedValidation = i18n.translateObject(validationMessages);
167
+ * // This allows you to easily get all validation messages in the current locale
168
+ * ```
169
+ *
170
+ * @note If the input object is not a valid object, an empty object of type T is returned.
171
+ * @note Only string values that are non-null and non-empty are translated; other values are skipped.
172
+ * @note This method is particularly useful for translating configuration objects, form labels,
173
+ * button texts, or any structured data containing translation keys.
174
+ *
175
+ * @see {@link translateTarget} for translating class properties decorated with @Translate
176
+ * @see {@link t} for translating individual keys with interpolation support
177
+ *
178
+ */
179
+ translateObject<T extends Record<string, string>>(object: T, options?: TranslateOptions): T;
180
+ /***
181
+ * returns the translation keys for the target class
182
+ * @param target the target class
183
+ * @returns the translation keys for the target class
184
+ */
185
+ static getTargetTanslationKeys<T extends ClassConstructor>(target: T): Record<keyof T, string>;
186
+ private _isLoading;
187
+ /***
188
+ * locales that are superted by the i18n instance
189
+ */
190
+ private _locales;
191
+ /**
192
+ * Namespace resolvers for loading translations.
193
+ */
194
+ private namespaceResolvers;
195
+ /**
196
+ * Singleton instance of the I18n class.
197
+ */
198
+ private static instance;
199
+ /**
200
+ * Creates an instance of the I18n class.
201
+ * @param options Optional configuration options for the I18n instance.
202
+ */
203
+ constructor(translations?: I18nTranslation, options?: Partial<I18nOptions>);
204
+ readonly _observableFactory: {
205
+ _____isObservable?: boolean;
206
+ on: (event: I18nEvent, fn: ObservableCallback) => {
207
+ remove: () => any;
208
+ };
209
+ finally: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
210
+ off: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
211
+ trigger: (event: "*" | I18nEvent, ...args: any[]) => /*elided*/ any;
212
+ offAll: () => /*elided*/ any;
213
+ once: (event: I18nEvent, fn: ObservableCallback) => {
214
+ remove: () => any;
215
+ };
216
+ getEventCallBacks: () => Partial<Record<"*" | I18nEvent, ObservableCallback[]>>;
217
+ };
218
+ readonly _____isObservable?: boolean | undefined;
219
+ /**
220
+ * Subscribes a callback function to a specific event.
221
+ * @param event The event name to listen for.
222
+ * @param fn The callback function to be invoked when the event is triggered.
223
+ * @returns An object containing a remove method to unsubscribe from the event.
224
+ */
225
+ on(event: I18nEvent, fn: ObservableCallback): {
226
+ remove: () => any;
227
+ };
228
+ /**
229
+ * Registers a callback to be invoked finally when an event is triggered.
230
+ * @param event The event name.
231
+ * @param fn The callback function to be invoked.
232
+ * @returns The observable instance.
233
+ */
234
+ finally(event: I18nEvent, fn: ObservableCallback): {
235
+ _____isObservable?: boolean;
236
+ on: (event: I18nEvent, fn: ObservableCallback) => {
237
+ remove: () => any;
238
+ };
239
+ finally: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
240
+ off: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
241
+ trigger: (event: "*" | I18nEvent, ...args: any[]) => /*elided*/ any;
242
+ offAll: () => /*elided*/ any;
243
+ once: (event: I18nEvent, fn: ObservableCallback) => {
244
+ remove: () => any;
245
+ };
246
+ getEventCallBacks: () => Partial<Record<"*" | I18nEvent, ObservableCallback[]>>;
247
+ };
248
+ /**
249
+ * Unsubscribes a callback from a specific event.
250
+ * @param event The event name.
251
+ * @param fn The callback function to remove.
252
+ * @returns The observable instance.
253
+ */
254
+ off(event: I18nEvent, fn: ObservableCallback): {
255
+ _____isObservable?: boolean;
256
+ on: (event: I18nEvent, fn: ObservableCallback) => {
257
+ remove: () => any;
258
+ };
259
+ finally: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
260
+ off: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
261
+ trigger: (event: "*" | I18nEvent, ...args: any[]) => /*elided*/ any;
262
+ offAll: () => /*elided*/ any;
263
+ once: (event: I18nEvent, fn: ObservableCallback) => {
264
+ remove: () => any;
265
+ };
266
+ getEventCallBacks: () => Partial<Record<"*" | I18nEvent, ObservableCallback[]>>;
267
+ };
268
+ /**
269
+ * Triggers a specific event with optional arguments.
270
+ * @param event The event name to trigger.
271
+ * @param args Optional arguments to pass to the event callbacks.
272
+ * @returns The observable instance.
273
+ */
274
+ trigger(event: I18nEvent | '*', ...args: any[]): {
275
+ _____isObservable?: boolean;
276
+ on: (event: I18nEvent, fn: ObservableCallback) => {
277
+ remove: () => any;
278
+ };
279
+ finally: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
280
+ off: (event: I18nEvent, fn: ObservableCallback) => /*elided*/ any;
281
+ trigger: (event: "*" | I18nEvent, ...args: any[]) => /*elided*/ any;
282
+ offAll: () => /*elided*/ any;
283
+ once: (event: I18nEvent, fn: ObservableCallback) => {
284
+ remove: () => any;
285
+ };
286
+ getEventCallBacks: () => Partial<Record<"*" | I18nEvent, ObservableCallback[]>>;
287
+ };
288
+ /**
289
+ * Unsubscribes all event callbacks for this component.
290
+ * @returns The observable instance.
291
+ */
292
+ offAll(): Observable<I18nEvent>;
293
+ /**
294
+ * Subscribes a callback function to be triggered once for a specific event.
295
+ * @param event The event name.
296
+ * @param fn The callback function to be invoked.
297
+ * @returns An object containing a remove method to unsubscribe from the event.
298
+ */
299
+ once(event: I18nEvent, fn: ObservableCallback): {
300
+ remove: () => any;
301
+ };
302
+ /**
303
+ * Retrieves all registered event callbacks.
304
+ * @returns An object mapping event names to their respective callback functions.
305
+ */
306
+ getEventCallBacks(): Partial<Record<"*" | I18nEvent, ObservableCallback[]>>;
307
+ /**
308
+ * Retrieves the singleton instance of the I18n class.
309
+ * @returns The singleton I18n instance.
310
+ */
311
+ static getInstance(options?: I18nOptions): I18n;
312
+ /***
313
+ * returns true if the instance is the default instance.
314
+ * @returns true if the instance is the default instance.
315
+ */
316
+ isDefaultInstance(): boolean;
317
+ private static setLocaleToSession;
318
+ static getLocaleFromSession(): any;
319
+ /**
320
+ * Checks if the provided translation key can be pluralized for the given locale.
321
+ * @param scope The translation scope to check.
322
+ * @param locale The locale to use for the check. If not provided, the current locale is used.
323
+ * @returns `true` if the translation key can be pluralized, `false` otherwise.
324
+ * @note This method is useful for determining if a translation key can be pluralized for a specific locale.
325
+ * A translation key can be pluralized if it has pluralization rules defined in the translation dictionary.
326
+ * The pluralization rules are defined in the `one`, `other`, and `zero` properties of the translation dictionary.
327
+ * @example
328
+ * //register a translation dictionary for the "en" locale.
329
+ * i18n.registerTranslations({
330
+ * en: {
331
+ * greeting: {
332
+ * one: "Hello, {name}!",
333
+ * other: "Hello, {name}s!",
334
+ * zero: "Hello, {name}s!"
335
+ * },
336
+ * farewell: "Goodbye!"
337
+ * }
338
+ * );
339
+ * });
340
+ * // Check if the translation key "greeting" can be pluralized for the current locale.
341
+ * i18n.canPluralize("greeting");
342
+ *
343
+ * // Check if the translation key "greeting" can be pluralized for the "en" locale.
344
+ * i18n.canPluralize("greeting", "en");
345
+ * i18n.canPluralize("greeting", "fr"); // returns false
346
+ * i18n.canPluralize("farewell", "en"); // returns false
347
+ */
348
+ canPluralize(scope: Scope, locale?: string): boolean;
349
+ /**
350
+ * Resolves translation for nested keys.
351
+ * @param scope {Scope} The translation scope.
352
+ * @param locale The locale to use for translation.
353
+ * @returns The translated string or undefined if not found.
354
+ * @example
355
+ * // Register translations for the "en" locale.
356
+ * i18n.registerTranslations({
357
+ * en: {
358
+ * greeting: {
359
+ * one: "Hello, {name}!",
360
+ * other: "Hello, {name}s!",
361
+ * zero: "Hello, {name}s!"
362
+ * },
363
+ * farewell: "Goodbye!"
364
+ * }
365
+ * });
366
+ *
367
+ * // Resolve translation for the "greeting" key.
368
+ * i18n.getNestedTranslation("greeting.one", "en");
369
+ *
370
+ * // Resolve translation for the "greeting" key.
371
+ * i18n.getNestedTranslation("greeting.other", "en");
372
+ *
373
+ * // Resolve translation for the "greeting" key.
374
+ * i18n.getNestedTranslation("en", "greeting.zero", 0);
375
+ *
376
+ * // Resolve translation for the "farewell" key.
377
+ * i18n.getNestedTranslation("en", "farewell");
378
+ */
379
+ getNestedTranslation(scope: Scope, locale?: string): string | Dictionary | undefined;
380
+ /**
381
+ * Checks if the provided `TranslateOptions` object has a `count` property of type `number`.
382
+ * This is used to determine if the translation should be pluralized based on the provided count.
383
+ * @param options The `TranslateOptions` object to check.
384
+ * @returns `true` if the `options` object has a `count` property of type `number`, `false` otherwise.
385
+ */
386
+ isPluralizeOptions(options?: TranslateOptions): options is TranslateOptions;
387
+ /**
388
+ * static function to attach translations to the I18n default instance.
389
+ @example :
390
+ // --- Usage as a decorator ---
391
+ I18n.RegisterTranslations({
392
+ de: {
393
+ greeting: "Hallo, {name}!",
394
+ farewell: "Auf Wiedersehen!",
395
+ },
396
+ })
397
+ * @param translations The language translations.
398
+ */
399
+ static RegisterTranslations(translations: I18nTranslation): I18nTranslation;
400
+ /**
401
+ * Factory method to create I18n instances dynamically.
402
+ * @param options Optional configuration options for the I18n instance.
403
+ * @returns A new I18n instance.
404
+ */
405
+ static createInstance(translations?: I18nTranslation, options?: Partial<I18nOptions> & {
406
+ interpolate?: (i18n: I18nJs, str: string, params: Dictionary) => string;
407
+ }): I18n;
408
+ /**
409
+ * Gets the translations for the specified locale, or all translations if no locale is provided.
410
+ * @param locale The locale to get translations for. If not provided, returns all translations.
411
+ * @returns The translations for the specified locale, or all translations if no locale is provided.
412
+ * @example
413
+ * // Get all translations
414
+ * const translations = i18n.getTranslations();
415
+ * console.log(translations);
416
+ *
417
+ * // Get translations for the "en" locale
418
+ * const enTranslations = i18n.getTranslations("en");
419
+ * console.log(enTranslations);
420
+ */
421
+ getTranslations(locale?: string): any;
422
+ /***
423
+ * list of registered moment locales
424
+ */
425
+ private static momentLocales;
426
+ private hasRegisteredDefaultTranslations;
427
+ /***
428
+ * register a moment locale
429
+ * @param {string} locale
430
+ * @param {LocaleSpecification} momentLocale
431
+ * @see https://momentjs.com/docs/#/customization/ for more information on customizing moment locales
432
+ * @see https://momentjs.com/docs/#/i18n/ for more information on moment locales
433
+ * @returns
434
+ */
435
+ static registerMomentLocale(locale: string, momentLocale: LocaleSpecification): Record<string, LocaleSpecification>;
436
+ /***
437
+ * get a registered moment locale
438
+ * @param {string} locale
439
+ * @returns {LocaleSpecification}
440
+ */
441
+ static getMomentLocale(locale: string): LocaleSpecification;
442
+ /***
443
+ * set a moment locale. the locale is picked from the momentLocales list
444
+ * @param {string} locale
445
+ * @param {Moment} momentInstance, The moment instance to set the locale on
446
+ * @returns {boolean}
447
+ */
448
+ static setMomentLocale(locale: string): boolean;
449
+ /**
450
+ * Registers translations into the I18n manager.
451
+ * @param translations The translations to register.
452
+ * @returns The updated translations.
453
+ */
454
+ registerTranslations(translations: I18nTranslation): I18nTranslation;
455
+ /**
456
+ * Stores the provided translations and triggers a "translations-changed" event with the current locale and translations.
457
+ * @param translations The translations to store.
458
+ */
459
+ store(translations: Dict): void;
460
+ /**
461
+ * Automatically resolves translations using reflect Metadata.
462
+ * Translations created using the @Translate decorator will be resolved.
463
+ * @param target The target class instance or object.
464
+ * @example
465
+ * // Class with translations using the decorator
466
+ * class MyComponent {
467
+ * @Translate("greeting")
468
+ * public greeting: string;
469
+ *
470
+ * @Translate("nested.example")
471
+ * public nestedExample: string;
472
+ *
473
+ * @Translate("farewell")
474
+ * public sayGoodbye(): string {
475
+ * return "";
476
+ * }
477
+ * }
478
+ * // Resolve translations and print them
479
+ * const component = new MyComponent();
480
+ * I18n.getInstance().resolveTranslations(component);
481
+ */
482
+ resolveTranslations<T extends object>(target: T): void;
483
+ /***
484
+ * returns the missing placeholder string for the given placeholder and message.
485
+ * @param placeholder - The placeholder to be replaced.
486
+ * @param message - The message to be displayed.
487
+ * @param options - The options for the missing placeholder string.
488
+ * @returns The missing placeholder string.
489
+ */
490
+ getMissingPlaceholderString(placeholder: string, message?: string, options?: I18nTranslation): string;
491
+ /**
492
+ * Gets the current locale for the i18n instance.
493
+ * @returns {string} The current locale.
494
+ */
495
+ getLocale(): string;
496
+ /**
497
+ * Sets the list of supported locales for the i18n instance.
498
+ * @param locales - An array of locale strings to set as the supported locales.
499
+ * @returns The list of all locales supported by the i18n instance, including both the locales for which translations are available and the locales explicitly set as supported.
500
+ */
501
+ setLocales(locales: string[]): string[];
502
+ /***
503
+ * returns true if the locale is supported by a i18n instance.
504
+ * @param locale - The locale to check.
505
+ * @returns true if the locale is supported, false otherwise.
506
+ */
507
+ hasLocale(locale: string): boolean;
508
+ /**
509
+ * Gets the list of all locales supported by the i18n instance, including both the locales for which translations are available and the locales explicitly set as supported.
510
+ * @returns {string[]} The list of all supported locales.
511
+ */
512
+ getLocales(): string[];
513
+ /***
514
+ * returns true if the locale is supported by the i18n instance.
515
+ * @param locale - The locale to check.
516
+ * @returns true if the locale is supported, false otherwise.
517
+ */
518
+ isLocaleSupported(locale: string): boolean;
519
+ /***
520
+ * returns true if the instance is loading translations.
521
+ * @returns true if the instance is loading translations, false otherwise.
522
+ * @example
523
+ * // Check if the instance is loading translations.
524
+ * i18n.isLoading();
525
+ */
526
+ isLoading(): boolean;
527
+ private _namespacesLoaded;
528
+ setLocale(locale: string, forceUpdate?: boolean): Promise<string>;
529
+ /**
530
+ * Register a namespace resolver.
531
+ * @param namespace The namespace to register.
532
+ * @param resolver The resolver function to load the namespace.
533
+ * @example
534
+ * // Register a namespace resolver for the "common" namespace.
535
+ * i18n.registerNamespaceResolver("common", async (locale) => {
536
+ * const response = await fetch(`/i18n/${locale}/common.json`);
537
+ * return await response.json();
538
+ * });
539
+ */
540
+ registerNamespaceResolver(namespace: string, resolver: (locale: string) => Promise<I18nTranslation>): void;
541
+ /**
542
+ * Static method to register a namespace resolver to the I18n default instance.
543
+ * @param namespace, The namespace to register.
544
+ * @param resolver, The resolver function to load the namespace.
545
+ * @returns
546
+ * @example
547
+ * // Register a namespace resolver for the "common" namespace.
548
+ * I18n.RegisterNamespaceResolver("common", async (locale) => {
549
+ * const response = await fetch(`/i18n/${locale}/common.json`);
550
+ * return await response.json();
551
+ * });
552
+ */
553
+ static RegisterNamespaceResolver(namespace: string, resolver: (locale: string) => Promise<any>): void;
554
+ loadNamespace(namespace: string, locale?: string, updateTranslations?: boolean): Promise<I18nTranslation>;
555
+ static LoadNamespace(namespace: string, locale?: string, updateTranslations?: boolean): Promise<I18nTranslation>;
556
+ loadNamespaces(locale?: string, updateTranslations?: boolean): Promise<I18nTranslation>;
557
+ /***
558
+ * Load all registered namespaces for the current locale on the I18n default instance.
559
+ * @param locale optional locale to load the namespaces for
560
+ * @param updateTranslations optional boolean to update the translations
561
+ * @returns {Promise<I18nTranslation>} A promise that resolves to the combined translations for the current local
562
+ */
563
+ static LoadNamespaces(locale?: string, updateTranslations?: boolean): Promise<I18nTranslation>;
564
+ /**
565
+ * Flattens a nested object into a single-level object with dot-notation keys.
566
+ *
567
+ * This utility method transforms complex nested objects into flat key-value pairs,
568
+ * where nested properties are represented using dot notation (e.g., `user.name`).
569
+ * This is particularly useful for interpolation processes that need to access
570
+ * nested values using simple string keys.
571
+ *
572
+ * @param obj - The object to flatten. Can be any type.
573
+ * @returns A flattened object where nested properties are accessible via dot-notation keys,
574
+ * or the original input if it's not an object.
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * // Basic flattening
579
+ * const nested = {
580
+ * user: {
581
+ * name: 'John',
582
+ * profile: {
583
+ * age: 30,
584
+ * city: 'New York'
585
+ * }
586
+ * },
587
+ * settings: { theme: 'dark' }
588
+ * };
589
+ *
590
+ * const flattened = I18n.flattenObject(nested);
591
+ * // Result: {
592
+ * // 'user.name': 'John',
593
+ * // 'user.profile.age': 30,
594
+ * // 'user.profile.city': 'New York',
595
+ * // 'settings.theme': 'dark'
596
+ * // }
597
+ * ```
598
+ *
599
+ * @example
600
+ * ```typescript
601
+ * // Non-object inputs are returned as-is
602
+ * I18n.flattenObject("string"); // Returns: "string"
603
+ * I18n.flattenObject(42); // Returns: 42
604
+ * I18n.flattenObject(null); // Returns: null
605
+ * ```
606
+ *
607
+ * @example
608
+ * ```typescript
609
+ * // Usage in interpolation
610
+ * const params = { user: { firstName: 'John', lastName: 'Doe' } };
611
+ * const flattened = I18n.flattenObject(params);
612
+ * // Now flattened can be used for interpolation like:
613
+ * // "Hello %{user.firstName} %{user.lastName}" -> "Hello John Doe"
614
+ * ```
615
+ *
616
+ * @note This method relies on `Object.flatten()` which should be available
617
+ * in the environment. If the input is not an object, it is returned unchanged.
618
+ * @note Circular references in objects may cause issues during flattening.
619
+ * @note Arrays are treated as objects and their indices become keys in the flattened result.
620
+ *
621
+ * @see {@link defaultInterpolator} for how this method is used in string interpolation.
622
+ */
623
+ static flattenObject(obj: any): TranslateOptions;
624
+ /**
625
+ * Provides a default interpolation function for the I18n instance.
626
+ *
627
+ * If the input `value` is `undefined` or `null`, an empty string is returned.
628
+ * If the input `value` is not a number, boolean, or string, it is converted to a string using `stringify`.
629
+ * If the input `params` is not an object, the `value` is returned as-is.
630
+ * If the input `params` is an object, the `value` is replaced with any matching placeholders in the format `%{key}` using the corresponding values from the `params` object.
631
+ *
632
+ * @param i18n The I18n instance.
633
+ * @param value The input value to be interpolated.
634
+ * @param params Optional object containing replacement values for placeholders in the `value`.
635
+ * @returns The interpolated string.
636
+ */
637
+ private static defaultInterpolator;
638
+ }
639
+ declare const i18n: I18n;
640
+ export { i18n };