@temboplus/frontend-core 0.2.5 → 0.2.6

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 (86) hide show
  1. package/README.md +63 -14
  2. package/esm/src/data/countries.d.ts +12 -2
  3. package/esm/src/data/countries.js +496 -248
  4. package/esm/src/models/amount/amount.d.ts.map +1 -1
  5. package/esm/src/models/amount/amount.js +1 -1
  6. package/esm/src/models/bank/bank.d.ts +127 -0
  7. package/esm/src/models/bank/bank.d.ts.map +1 -1
  8. package/esm/src/models/bank/bank.js +264 -7
  9. package/esm/src/models/bank/index.d.ts +0 -1
  10. package/esm/src/models/bank/index.d.ts.map +1 -1
  11. package/esm/src/models/bank/index.js +0 -1
  12. package/esm/src/models/country/country.d.ts +162 -24
  13. package/esm/src/models/country/country.d.ts.map +1 -1
  14. package/esm/src/models/country/country.js +442 -42
  15. package/esm/src/models/country/index.d.ts +1 -1
  16. package/esm/src/models/country/index.d.ts.map +1 -1
  17. package/esm/src/models/country/index.js +1 -1
  18. package/esm/src/models/country/types.d.ts +53 -0
  19. package/esm/src/models/country/types.d.ts.map +1 -0
  20. package/esm/src/models/country/types.js +43 -0
  21. package/esm/src/models/currency/currency.d.ts +127 -4
  22. package/esm/src/models/currency/currency.d.ts.map +1 -1
  23. package/esm/src/models/currency/currency.js +229 -11
  24. package/esm/src/models/currency/index.d.ts +1 -1
  25. package/esm/src/models/currency/index.d.ts.map +1 -1
  26. package/esm/src/models/currency/index.js +1 -1
  27. package/esm/src/models/currency/types.d.ts +20 -0
  28. package/esm/src/models/currency/types.d.ts.map +1 -0
  29. package/esm/src/models/currency/types.js +13 -0
  30. package/esm/src/models/phone_number/global/phone_number.d.ts +3 -2
  31. package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -1
  32. package/esm/src/models/phone_number/global/service.d.ts +27 -20
  33. package/esm/src/models/phone_number/global/service.d.ts.map +1 -1
  34. package/esm/src/models/phone_number/global/service.js +61 -40
  35. package/package.json +1 -1
  36. package/script/src/data/countries.d.ts +12 -2
  37. package/script/src/data/countries.js +496 -248
  38. package/script/src/models/amount/amount.d.ts.map +1 -1
  39. package/script/src/models/amount/amount.js +4 -4
  40. package/script/src/models/bank/bank.d.ts +127 -0
  41. package/script/src/models/bank/bank.d.ts.map +1 -1
  42. package/script/src/models/bank/bank.js +273 -12
  43. package/script/src/models/bank/index.d.ts +0 -1
  44. package/script/src/models/bank/index.d.ts.map +1 -1
  45. package/script/src/models/bank/index.js +0 -1
  46. package/script/src/models/country/country.d.ts +162 -24
  47. package/script/src/models/country/country.d.ts.map +1 -1
  48. package/script/src/models/country/country.js +453 -49
  49. package/script/src/models/country/index.d.ts +1 -1
  50. package/script/src/models/country/index.d.ts.map +1 -1
  51. package/script/src/models/country/index.js +1 -1
  52. package/script/src/models/country/types.d.ts +53 -0
  53. package/script/src/models/country/types.d.ts.map +1 -0
  54. package/script/src/models/country/types.js +46 -0
  55. package/script/src/models/currency/currency.d.ts +127 -4
  56. package/script/src/models/currency/currency.d.ts.map +1 -1
  57. package/script/src/models/currency/currency.js +237 -15
  58. package/script/src/models/currency/index.d.ts +1 -1
  59. package/script/src/models/currency/index.d.ts.map +1 -1
  60. package/script/src/models/currency/index.js +1 -1
  61. package/script/src/models/currency/types.d.ts +20 -0
  62. package/script/src/models/currency/types.d.ts.map +1 -0
  63. package/script/src/models/currency/types.js +14 -0
  64. package/script/src/models/phone_number/global/phone_number.d.ts +3 -2
  65. package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -1
  66. package/script/src/models/phone_number/global/service.d.ts +27 -20
  67. package/script/src/models/phone_number/global/service.d.ts.map +1 -1
  68. package/script/src/models/phone_number/global/service.js +61 -40
  69. package/esm/src/models/bank/service.d.ts +0 -106
  70. package/esm/src/models/bank/service.d.ts.map +0 -1
  71. package/esm/src/models/bank/service.js +0 -240
  72. package/esm/src/models/country/service.d.ts +0 -111
  73. package/esm/src/models/country/service.d.ts.map +0 -1
  74. package/esm/src/models/country/service.js +0 -366
  75. package/esm/src/models/currency/service.d.ts +0 -96
  76. package/esm/src/models/currency/service.d.ts.map +0 -1
  77. package/esm/src/models/currency/service.js +0 -194
  78. package/script/src/models/bank/service.d.ts +0 -106
  79. package/script/src/models/bank/service.d.ts.map +0 -1
  80. package/script/src/models/bank/service.js +0 -247
  81. package/script/src/models/country/service.d.ts +0 -111
  82. package/script/src/models/country/service.d.ts.map +0 -1
  83. package/script/src/models/country/service.js +0 -373
  84. package/script/src/models/currency/service.d.ts +0 -96
  85. package/script/src/models/currency/service.d.ts.map +0 -1
  86. package/script/src/models/currency/service.js +0 -201
@@ -1,373 +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.CountryService = void 0;
7
- const country_js_1 = require("./country.js");
8
- const countries_js_1 = __importDefault(require("../../data/countries.js"));
9
- /**
10
- * Service for managing country data.
11
- * @class CountryService
12
- */
13
- class CountryService {
14
- constructor() {
15
- Object.defineProperty(this, "countryList", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: []
20
- });
21
- Object.defineProperty(this, "codeRecord", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: {}
26
- });
27
- Object.defineProperty(this, "iso3Record", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: {}
32
- });
33
- // private nameRecord: Record<string, Country> = {};
34
- Object.defineProperty(this, "nameRecord", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: {}
39
- });
40
- Object.defineProperty(this, "continentRecord", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: {}
45
- });
46
- Object.defineProperty(this, "regionRecord", {
47
- enumerable: true,
48
- configurable: true,
49
- writable: true,
50
- value: {}
51
- });
52
- // Static references for direct access through Country class
53
- Object.defineProperty(this, "staticReferences", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: new Map()
58
- });
59
- }
60
- /**
61
- * Gets the singleton instance of CountryService.
62
- * Creates the instance if it doesn't exist.
63
- * @static
64
- * @returns {CountryService} The singleton instance
65
- */
66
- static getInstance() {
67
- if (!CountryService.instance) {
68
- CountryService.instance = new CountryService();
69
- CountryService.instance.initialize();
70
- }
71
- return CountryService.instance;
72
- }
73
- /**
74
- * Maps a string continent name to the CONTINENT enum
75
- * @param continentName String continent name from JSON
76
- * @returns The corresponding CONTINENT enum value
77
- */
78
- mapContinent(continentName) {
79
- switch (continentName) {
80
- case "Africa":
81
- return country_js_1.CONTINENT.AFRICA;
82
- case "Antarctica":
83
- return country_js_1.CONTINENT.ANTARCTICA;
84
- case "Asia":
85
- return country_js_1.CONTINENT.ASIA;
86
- case "Europe":
87
- return country_js_1.CONTINENT.EUROPE;
88
- case "North America":
89
- return country_js_1.CONTINENT.NORTH_AMERICA;
90
- case "Oceania":
91
- return country_js_1.CONTINENT.OCEANIA;
92
- case "South America":
93
- return country_js_1.CONTINENT.SOUTH_AMERICA;
94
- default:
95
- return country_js_1.CONTINENT.EUROPE; // Default value
96
- }
97
- }
98
- /**
99
- * Maps a string region name to the SUB_REGION enum
100
- * @param regionName String region name from JSON
101
- * @returns The corresponding SUB_REGION enum value
102
- */
103
- mapRegion(regionName) {
104
- switch (regionName) {
105
- case "Australia and New Zealand":
106
- return country_js_1.SUB_REGION.AUSTRALIA_AND_NEW_ZEALAND;
107
- case "Caribbean":
108
- return country_js_1.SUB_REGION.CARIBBEAN;
109
- case "Central America":
110
- return country_js_1.SUB_REGION.CENTRAL_AMERICA;
111
- case "Central Asia":
112
- return country_js_1.SUB_REGION.CENTRAL_ASIA;
113
- case "Eastern Africa":
114
- return country_js_1.SUB_REGION.EASTERN_AFRICA;
115
- case "Eastern Asia":
116
- return country_js_1.SUB_REGION.EASTERN_ASIA;
117
- case "Eastern Europe":
118
- return country_js_1.SUB_REGION.EASTERN_EUROPE;
119
- case "Melanesia":
120
- return country_js_1.SUB_REGION.MELANESIA;
121
- case "Micronesia":
122
- return country_js_1.SUB_REGION.MICRONESIA;
123
- case "Middle Africa":
124
- return country_js_1.SUB_REGION.MIDDLE_AFRICA;
125
- case "Northern Africa":
126
- return country_js_1.SUB_REGION.NORTHERN_AFRICA;
127
- case "Northern America":
128
- return country_js_1.SUB_REGION.NORTHERN_AMERICA;
129
- case "Northern Europe":
130
- return country_js_1.SUB_REGION.NORTHERN_EUROPE;
131
- case "Polynesia":
132
- return country_js_1.SUB_REGION.POLYNESIA;
133
- case "South-eastern Asia":
134
- return country_js_1.SUB_REGION.SOUTH_EASTERN_ASIA;
135
- case "Southern Africa":
136
- return country_js_1.SUB_REGION.SOUTHERN_AFRICA;
137
- case "Southern Asia":
138
- return country_js_1.SUB_REGION.SOUTHERN_ASIA;
139
- case "Southern Europe":
140
- return country_js_1.SUB_REGION.SOUTHERN_EUROPE;
141
- case "Western Africa":
142
- return country_js_1.SUB_REGION.WESTERN_AFRICA;
143
- case "Western Asia":
144
- return country_js_1.SUB_REGION.WESTERN_ASIA;
145
- case "Western Europe":
146
- return country_js_1.SUB_REGION.WESTERN_EUROPE;
147
- default:
148
- return country_js_1.SUB_REGION.NORTHERN_EUROPE; // Default value
149
- }
150
- }
151
- /**
152
- * Initializes the service with country data.
153
- * Should be called once when your application starts.
154
- */
155
- initialize() {
156
- try {
157
- // Parse the JSON data
158
- const data = JSON.parse(JSON.stringify(countries_js_1.default));
159
- // deno-lint-ignore no-explicit-any
160
- const countriesData = data.countries || [];
161
- // Initialize continent and region records
162
- Object.values(country_js_1.CONTINENT).forEach((continent) => {
163
- this.continentRecord[continent] = [];
164
- });
165
- Object.values(country_js_1.SUB_REGION).forEach((region) => {
166
- this.regionRecord[region] = [];
167
- });
168
- // Create Country instances from the data
169
- const countries = countriesData.map((c) => {
170
- const continent = this.mapContinent(c.continent);
171
- const region = this.mapRegion(c.region);
172
- return new country_js_1.Country(c.name, c.iso_2, c.name_official, c.iso_3, c.flag_emoji, continent, region);
173
- });
174
- const code_record = {};
175
- const iso3_record = {};
176
- // const name_record: Record<string, Country> = {};
177
- const name_record = {};
178
- countries.forEach((country) => {
179
- // Populate code records
180
- code_record[country.code] = country;
181
- iso3_record[country.iso3] = country;
182
- // Add to record by name
183
- // name_record[country.name.toUpperCase()] = country;
184
- // Generate uppercase full name with underscores
185
- const nameKey = country.name
186
- .toUpperCase()
187
- .replace(/\s+/g, "_")
188
- .replace(/[-(),.']/g, "")
189
- .replace(/&/g, "AND");
190
- name_record[nameKey] = country;
191
- // Group countries by continent
192
- this.continentRecord[country.continent].push(country);
193
- // Group countries by region
194
- this.regionRecord[country.region].push(country);
195
- this.staticReferences.set(country.code, country);
196
- this.staticReferences.set(nameKey, country);
197
- });
198
- // Add specific country mappings for special cases
199
- // Cocos Islands
200
- if (code_record["CC"]) {
201
- name_record["COCOS_ISLANDS"] = code_record["CC"];
202
- this.staticReferences.set("COCOS_ISLANDS", code_record["CC"]);
203
- }
204
- // Cote d'Ivoire
205
- if (code_record["CI"]) {
206
- name_record["COTE_DIVOIRE"] = code_record["CI"];
207
- this.staticReferences.set("COTE_DIVOIRE", code_record["CI"]);
208
- }
209
- // Macedonia (North Macedonia)
210
- if (code_record["MK"]) {
211
- name_record["MACEDONIA"] = code_record["MK"];
212
- this.staticReferences.set("MACEDONIA", code_record["MK"]);
213
- }
214
- // US Virgin Islands
215
- if (code_record["VI"]) {
216
- name_record["VIRGIN_ISLANDS_US"] = code_record["VI"];
217
- this.staticReferences.set("VIRGIN_ISLANDS_US", code_record["VI"]);
218
- }
219
- // British Virgin Islands
220
- if (code_record["VG"]) {
221
- name_record["VIRGIN_ISLANDS_BRITISH"] = code_record["VG"];
222
- this.staticReferences.set("VIRGIN_ISLANDS_BRITISH", code_record["VG"]);
223
- }
224
- // Democratic Republic of the Congo
225
- if (code_record["CD"]) {
226
- name_record["DEMOCRATIC_REPUBLIC_OF_CONGO"] = code_record["CD"];
227
- this.staticReferences.set("DEMOCRATIC_REPUBLIC_OF_CONGO", code_record["CD"]);
228
- }
229
- // Falkland Islands (Malvinas)
230
- if (code_record["FK"]) {
231
- name_record["FALKLAND_ISLANDS"] = code_record["FK"];
232
- this.staticReferences.set("FALKLAND_ISLANDS", code_record["FK"]);
233
- }
234
- // Lao
235
- if (code_record["LA"]) {
236
- name_record["LAO"] = code_record["LA"];
237
- this.staticReferences.set("LAO", code_record["LA"]);
238
- }
239
- this.codeRecord = code_record;
240
- this.iso3Record = iso3_record;
241
- this.nameRecord = name_record;
242
- this.countryList = countries;
243
- // Initialize static properties on Country class
244
- this.initializeCountryStatics();
245
- }
246
- catch (error) {
247
- console.error("Failed to initialize CountryService:", error);
248
- }
249
- }
250
- /**
251
- * Initialize the static properties on the Country class
252
- */
253
- initializeCountryStatics() {
254
- // Initialize ISO-2 code properties
255
- Object.entries(this.codeRecord).forEach(([code, country]) => {
256
- // deno-lint-ignore no-explicit-any
257
- country_js_1.Country[code.toUpperCase()] = country;
258
- });
259
- // Initialize full name properties
260
- Object.entries(this.nameRecord).forEach(([fullName, country]) => {
261
- // deno-lint-ignore no-explicit-any
262
- country_js_1.Country[fullName] = country;
263
- });
264
- }
265
- /**
266
- * Gets all countries.
267
- * @returns {Country[]} Array of all countries
268
- */
269
- getAll() {
270
- return this.countryList;
271
- }
272
- /**
273
- * Gets static country references to be used by the Country class.
274
- * @returns {Map<string, Country>} Map of static references
275
- */
276
- getStaticReferences() {
277
- return this.staticReferences;
278
- }
279
- /**
280
- * Gets all countries as a record.
281
- * @returns {Record<string, Country>} Record of country codes and country objects
282
- */
283
- getAllAsRecord() {
284
- return this.codeRecord;
285
- }
286
- /**
287
- * Gets all countries from a specific continent.
288
- * @param {CONTINENT} continent The continent enum value
289
- * @returns {Country[]} Array of countries in the specified continent
290
- */
291
- getByContinent(continent) {
292
- return this.continentRecord[continent] || [];
293
- }
294
- /**
295
- * Gets all countries from a specific region.
296
- * @param {SUB_REGION} region The region enum value
297
- * @returns {Country[]} Array of countries in the specified region
298
- */
299
- getByRegion(region) {
300
- return this.regionRecord[region] || [];
301
- }
302
- /**
303
- * Gets the full name record mapping.
304
- * @returns {Record<string, Country>} Record of uppercase full name keys to country objects
305
- */
306
- getFullNameRecord() {
307
- return this.nameRecord;
308
- }
309
- /**
310
- * Retrieves a country by its ISO-2 code.
311
- * @param {string} code The ISO-2 code of the country.
312
- * @returns {Country | undefined} The country corresponding to the ISO code or `undefined` if not found.
313
- */
314
- fromCode(code) {
315
- return this.codeRecord[code.toUpperCase()];
316
- }
317
- /**
318
- * Retrieves a country by its ISO-3 code.
319
- * @param {string} iso3 The ISO-3 code of the country.
320
- * @returns {Country | undefined} The country corresponding to the ISO-3 code or `undefined` if not found.
321
- */
322
- fromIso3(iso3) {
323
- return this.iso3Record[iso3.toUpperCase()];
324
- }
325
- /**
326
- * Retrieves a country by its name.
327
- * @param {string} countryName The name of the country.
328
- * @returns {Country | undefined} The country corresponding to the name or `undefined` if not found.
329
- */
330
- fromName(countryName) {
331
- const fullNameKey = countryName
332
- .toUpperCase()
333
- .replace(/\s+/g, "_")
334
- .replace(/[-(),.']/g, "")
335
- .replace(/&/g, "AND");
336
- const fullNameMatch = this.nameRecord[fullNameKey];
337
- if (fullNameMatch)
338
- return fullNameMatch;
339
- // If not found, try more lenient matching
340
- return this.countryList.find((country) => country.name.toLowerCase() === countryName.toLowerCase());
341
- }
342
- /**
343
- * Searches for countries that match the given search term.
344
- * @param {string} searchTerm - The partial name or code to search for.
345
- * @param {number} [limit=10] - Maximum number of results to return.
346
- * @returns {Country[]} Array of matching countries, limited to specified count.
347
- */
348
- search(searchTerm, limit = 10) {
349
- if (!searchTerm || typeof searchTerm !== "string")
350
- return [];
351
- const term = searchTerm.toLowerCase().trim();
352
- if (term.length === 0)
353
- return [];
354
- const results = this.countryList.filter((country) => country.name.toLowerCase().includes(term) ||
355
- country.nameOfficial.toLowerCase().includes(term) ||
356
- country.code.toLowerCase().includes(term) ||
357
- country.iso3.toLowerCase().includes(term));
358
- return results.slice(0, limit);
359
- }
360
- /**
361
- * Compares two Country instances for equality by checking their name and code
362
- *
363
- * @param {Country} country1 - First country to compare
364
- * @param {Country} country2 - Second country to compare
365
- * @returns {boolean} True if countries are equal, false otherwise
366
- * @private
367
- */
368
- compare(country1, country2) {
369
- return (country1.name === country2.name &&
370
- country1.code === country2.code);
371
- }
372
- }
373
- exports.CountryService = CountryService;
@@ -1,96 +0,0 @@
1
- import { Currency } from "./currency.js";
2
- /**
3
- * Service for managing currency data.
4
- * @class CurrencyService
5
- */
6
- export declare class CurrencyService {
7
- private static instance;
8
- private currencyList;
9
- private currencyRecord;
10
- private nameRecord;
11
- private staticReferences;
12
- private constructor();
13
- /**
14
- * Gets the singleton instance of CurrencyService.
15
- * Creates the instance if it doesn't exist.
16
- * @static
17
- * @returns {CurrencyService} The singleton instance
18
- */
19
- static getInstance(): CurrencyService;
20
- /**
21
- * Initializes the service with currency data.
22
- * Should be called once when your application starts.
23
- */
24
- private initialize;
25
- /**
26
- * Gets all currencies.
27
- * @returns {Currency[]} Array of all currencies
28
- */
29
- getAll(): Currency[];
30
- /**
31
- * Gets all currencies as a record.
32
- * @returns {Record<string, Currency>} Record of currency codes and currency objects
33
- */
34
- getAllAsRecord(): Record<string, Currency>;
35
- /**
36
- * Gets static currency references to be used by the Currency class.
37
- * @returns {Map<string, Currency>} Map of static references
38
- */
39
- getStaticReferences(): Map<string, Currency>;
40
- /**
41
- * Retrieves a currency by its ISO code.
42
- * @param {string} code The ISO code of the currency.
43
- * @returns {Currency | undefined} The currency corresponding to the ISO code or `undefined` if not found.
44
- */
45
- fromCode(code: string): Currency | undefined;
46
- /**
47
- * Retrieves a currency by its name.
48
- * @param {string} currencyName The name of the currency.
49
- * @returns {Currency | undefined} The currency corresponding to the name or `undefined` if not found.
50
- */
51
- fromName(currencyName: string): Currency | undefined;
52
- /**
53
- * Validates if a given ISO currency code is valid
54
- *
55
- * @param {string | null | undefined} code - The currency code to validate.
56
- * Should be a three-letter ISO currency code (e.g., 'USD', 'EUR').
57
- *
58
- * @returns {boolean} Returns true if:
59
- * - The currency code is not null/undefined
60
- * - The currency code successfully resolves to a valid Currency instance
61
- * Returns false otherwise.
62
- */
63
- isValidCode(code?: string | null): boolean;
64
- /**
65
- * Validates if a given currency name is valid
66
- *
67
- * @param {string | null | undefined} currencyName - The currency name to validate.
68
- *
69
- * @returns {boolean} Returns true if:
70
- * - The currency name is not null/undefined
71
- * - The currency name successfully resolves to a valid Currency instance
72
- * Returns false otherwise.
73
- */
74
- isValidName(currencyName?: string | null): boolean;
75
- /**
76
- * Gets a regex-ready pattern matching all currency symbols
77
- * Pattern is memoized for performance
78
- * @returns {string} Pipe-separated pattern of escaped currency symbols
79
- *
80
- * @example
81
- * const pattern = currencyService.getCurrencySymbolPattern();
82
- * // Returns something like: "\$|€|\£|¥"
83
- */
84
- getCurrencySymbolPattern(): string;
85
- /**
86
- * Escapes special characters in a string for use in regular expressions
87
- * @private
88
- * @param {string} string - The string to escape
89
- * @returns {string} The escaped string
90
- *
91
- * @example
92
- * private escapeRegExp("$") // Returns "\$"
93
- */
94
- private escapeRegExp;
95
- }
96
- //# sourceMappingURL=service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/currency/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAiBzC;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAkB;IACzC,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,cAAc,CAAgC;IACtD,OAAO,CAAC,UAAU,CAAgC;IAGlD,OAAO,CAAC,gBAAgB,CAAoC;IAE5D,OAAO;IAEP;;;;;OAKG;IACH,MAAM,CAAC,WAAW,IAAI,eAAe;IAQrC;;;OAGG;IACH,OAAO,CAAC,UAAU;IAmDlB;;;OAGG;IACH,MAAM,IAAI,QAAQ,EAAE;IAIpB;;;OAGG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC;IAI1C;;;OAGG;IACH,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAmBpD;;;;;;;;;;OAUG;IACH,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAM1C;;;;;;;;;OASG;IACH,WAAW,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAMlD;;;;;;;;OAQG;IACH,wBAAwB,IAAI,MAAM;IAUlC;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;CAGrB"}
@@ -1,201 +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.CurrencyService = void 0;
7
- const currency_js_1 = require("./currency.js");
8
- const currencies_js_1 = __importDefault(require("../../data/currencies.js"));
9
- /**
10
- * Service for managing currency data.
11
- * @class CurrencyService
12
- */
13
- class CurrencyService {
14
- constructor() {
15
- Object.defineProperty(this, "currencyList", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: []
20
- });
21
- Object.defineProperty(this, "currencyRecord", {
22
- enumerable: true,
23
- configurable: true,
24
- writable: true,
25
- value: {}
26
- });
27
- Object.defineProperty(this, "nameRecord", {
28
- enumerable: true,
29
- configurable: true,
30
- writable: true,
31
- value: {}
32
- });
33
- // Static references for direct access through Currency class
34
- Object.defineProperty(this, "staticReferences", {
35
- enumerable: true,
36
- configurable: true,
37
- writable: true,
38
- value: new Map()
39
- });
40
- }
41
- /**
42
- * Gets the singleton instance of CurrencyService.
43
- * Creates the instance if it doesn't exist.
44
- * @static
45
- * @returns {CurrencyService} The singleton instance
46
- */
47
- static getInstance() {
48
- if (!CurrencyService.instance) {
49
- CurrencyService.instance = new CurrencyService();
50
- CurrencyService.instance.initialize();
51
- }
52
- return CurrencyService.instance;
53
- }
54
- /**
55
- * Initializes the service with currency data.
56
- * Should be called once when your application starts.
57
- */
58
- initialize() {
59
- try {
60
- const data = JSON.parse(JSON.stringify(currencies_js_1.default));
61
- const currencies = Object.values(data).map((c) => new currency_js_1.Currency(c.symbol, c.name, c.symbol_native, c.decimal_digits, c.rounding, c.code, c.name_plural));
62
- const codeRecord = {};
63
- const nameRecord = {};
64
- currencies.forEach((currency) => {
65
- // Populate code record
66
- codeRecord[currency.code] = currency;
67
- // Add to record by name
68
- nameRecord[currency.name.toUpperCase()] = currency;
69
- const upperCode = currency.code.toUpperCase();
70
- // Add to static references for uppercase code
71
- this.staticReferences.set(upperCode, currency);
72
- // Add formatted full name static reference based on name property
73
- // Transform from "US Dollar" to "US_DOLLAR"
74
- const nameKey = currency.name
75
- .toUpperCase()
76
- .replace(/\s+/g, "_")
77
- .replace(/[-(),.']/g, "")
78
- .replace(/&/g, "AND");
79
- this.staticReferences.set(nameKey, currency);
80
- });
81
- this.currencyRecord = codeRecord;
82
- this.nameRecord = nameRecord;
83
- this.currencyList = currencies;
84
- }
85
- catch (error) {
86
- console.error("Failed to initialize CurrencyService:", error);
87
- }
88
- }
89
- /**
90
- * Gets all currencies.
91
- * @returns {Currency[]} Array of all currencies
92
- */
93
- getAll() {
94
- return this.currencyList;
95
- }
96
- /**
97
- * Gets all currencies as a record.
98
- * @returns {Record<string, Currency>} Record of currency codes and currency objects
99
- */
100
- getAllAsRecord() {
101
- return this.currencyRecord;
102
- }
103
- /**
104
- * Gets static currency references to be used by the Currency class.
105
- * @returns {Map<string, Currency>} Map of static references
106
- */
107
- getStaticReferences() {
108
- return this.staticReferences;
109
- }
110
- /**
111
- * Retrieves a currency by its ISO code.
112
- * @param {string} code The ISO code of the currency.
113
- * @returns {Currency | undefined} The currency corresponding to the ISO code or `undefined` if not found.
114
- */
115
- fromCode(code) {
116
- return this.currencyRecord[code.trim().toUpperCase()];
117
- }
118
- /**
119
- * Retrieves a currency by its name.
120
- * @param {string} currencyName The name of the currency.
121
- * @returns {Currency | undefined} The currency corresponding to the name or `undefined` if not found.
122
- */
123
- fromName(currencyName) {
124
- const input = currencyName.trim().toUpperCase();
125
- // First try direct lookup in name record
126
- const directMatch = this.nameRecord[input];
127
- if (directMatch)
128
- return directMatch;
129
- // If not found, try more lenient matching
130
- for (const [name, currObj] of Object.entries(this.nameRecord)) {
131
- if (name.toUpperCase() === input) {
132
- return currObj;
133
- }
134
- }
135
- // Finally, try case-insensitive exact match
136
- return this.currencyList.find((currency) => currency.name.toUpperCase() === input);
137
- }
138
- /**
139
- * Validates if a given ISO currency code is valid
140
- *
141
- * @param {string | null | undefined} code - The currency code to validate.
142
- * Should be a three-letter ISO currency code (e.g., 'USD', 'EUR').
143
- *
144
- * @returns {boolean} Returns true if:
145
- * - The currency code is not null/undefined
146
- * - The currency code successfully resolves to a valid Currency instance
147
- * Returns false otherwise.
148
- */
149
- isValidCode(code) {
150
- if (!code)
151
- return false;
152
- const currency = this.fromCode(code);
153
- return !!currency;
154
- }
155
- /**
156
- * Validates if a given currency name is valid
157
- *
158
- * @param {string | null | undefined} currencyName - The currency name to validate.
159
- *
160
- * @returns {boolean} Returns true if:
161
- * - The currency name is not null/undefined
162
- * - The currency name successfully resolves to a valid Currency instance
163
- * Returns false otherwise.
164
- */
165
- isValidName(currencyName) {
166
- if (!currencyName)
167
- return false;
168
- const currency = this.fromName(currencyName);
169
- return !!currency;
170
- }
171
- /**
172
- * Gets a regex-ready pattern matching all currency symbols
173
- * Pattern is memoized for performance
174
- * @returns {string} Pipe-separated pattern of escaped currency symbols
175
- *
176
- * @example
177
- * const pattern = currencyService.getCurrencySymbolPattern();
178
- * // Returns something like: "\$|€|\£|¥"
179
- */
180
- getCurrencySymbolPattern() {
181
- const symbols = new Set();
182
- Object.values(this.currencyList).forEach((currency) => {
183
- symbols.add(this.escapeRegExp(currency.symbol));
184
- symbols.add(this.escapeRegExp(currency.symbolNative));
185
- });
186
- return Array.from(symbols).join("|");
187
- }
188
- /**
189
- * Escapes special characters in a string for use in regular expressions
190
- * @private
191
- * @param {string} string - The string to escape
192
- * @returns {string} The escaped string
193
- *
194
- * @example
195
- * private escapeRegExp("$") // Returns "\$"
196
- */
197
- escapeRegExp(string) {
198
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
199
- }
200
- }
201
- exports.CurrencyService = CurrencyService;