@temboplus/frontend-core 0.2.1 → 0.2.3

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 +126 -25
  2. package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  3. package/esm/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  4. package/esm/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  5. package/esm/mod.d.ts +2 -0
  6. package/esm/mod.d.ts.map +1 -1
  7. package/esm/mod.js +2 -0
  8. package/esm/src/config/config_service.d.ts +11 -0
  9. package/esm/src/config/config_service.d.ts.map +1 -0
  10. package/esm/src/config/config_service.js +19 -0
  11. package/esm/src/config/index.d.ts +2 -0
  12. package/esm/src/config/index.d.ts.map +1 -0
  13. package/esm/src/config/index.js +1 -0
  14. package/esm/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  15. package/esm/src/data/banks_tz.d.ts.map +1 -0
  16. package/esm/src/data/countries.d.ts +6 -0
  17. package/esm/src/data/countries.d.ts.map +1 -0
  18. package/esm/src/data/countries.js +974 -0
  19. package/esm/src/data/currencies.d.ts +1901 -0
  20. package/esm/src/data/currencies.d.ts.map +1 -0
  21. package/esm/src/data/currencies.js +1073 -0
  22. package/esm/src/data/phone_patterns.d.ts +3809 -0
  23. package/esm/src/data/phone_patterns.d.ts.map +1 -0
  24. package/esm/src/data/phone_patterns.js +2325 -0
  25. package/esm/src/models/amount/amount.d.ts +10 -12
  26. package/esm/src/models/amount/amount.d.ts.map +1 -1
  27. package/esm/src/models/amount/amount.js +58 -96
  28. package/esm/src/models/bank/bank.d.ts +58 -53
  29. package/esm/src/models/bank/bank.d.ts.map +1 -1
  30. package/esm/src/models/bank/bank.js +49 -84
  31. package/esm/src/models/bank/index.d.ts +1 -1
  32. package/esm/src/models/bank/index.d.ts.map +1 -1
  33. package/esm/src/models/bank/index.js +1 -1
  34. package/esm/src/models/bank/service.d.ts +106 -0
  35. package/esm/src/models/bank/service.d.ts.map +1 -0
  36. package/esm/src/models/bank/service.js +240 -0
  37. package/esm/src/models/country/country.d.ts +568 -0
  38. package/esm/src/models/country/country.d.ts.map +1 -0
  39. package/esm/src/models/country/country.js +165 -0
  40. package/esm/src/models/country/country.test.d.ts.map +1 -0
  41. package/esm/src/models/country/index.d.ts +3 -0
  42. package/esm/src/models/country/index.d.ts.map +1 -0
  43. package/esm/src/models/country/index.js +2 -0
  44. package/esm/src/models/country/service.d.ts +75 -0
  45. package/esm/src/models/country/service.d.ts.map +1 -0
  46. package/esm/src/models/country/service.js +267 -0
  47. package/esm/src/models/currency/currency.d.ts +341 -0
  48. package/esm/src/models/currency/currency.d.ts.map +1 -0
  49. package/esm/src/models/currency/currency.js +225 -0
  50. package/esm/src/models/currency/currency.test.d.ts.map +1 -0
  51. package/esm/src/models/currency/index.d.ts +3 -0
  52. package/esm/src/models/currency/index.d.ts.map +1 -0
  53. package/esm/src/models/currency/index.js +2 -0
  54. package/esm/src/models/currency/service.d.ts +96 -0
  55. package/esm/src/models/currency/service.d.ts.map +1 -0
  56. package/esm/src/models/currency/service.js +194 -0
  57. package/esm/src/models/index.d.ts +2 -0
  58. package/esm/src/models/index.d.ts.map +1 -1
  59. package/esm/src/models/index.js +2 -0
  60. package/esm/src/models/phone_number/format.d.ts +14 -0
  61. package/esm/src/models/phone_number/format.d.ts.map +1 -0
  62. package/esm/src/models/phone_number/format.js +14 -0
  63. package/esm/src/models/phone_number/global/phone_number.d.ts +160 -0
  64. package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  65. package/esm/src/models/phone_number/global/phone_number.js +453 -0
  66. package/esm/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  67. package/esm/src/models/phone_number/global/service.d.ts +260 -0
  68. package/esm/src/models/phone_number/global/service.d.ts.map +1 -0
  69. package/esm/src/models/phone_number/global/service.js +477 -0
  70. package/esm/src/models/phone_number/global/service.test.d.ts.map +1 -0
  71. package/esm/src/models/phone_number/index.d.ts +5 -3
  72. package/esm/src/models/phone_number/index.d.ts.map +1 -1
  73. package/esm/src/models/phone_number/index.js +5 -3
  74. package/esm/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  75. package/esm/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  76. package/esm/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +2 -2
  77. package/esm/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  78. package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  79. package/{script/src/models/phone_number → esm/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  80. package/esm/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  81. package/esm/src/models/phone_number/{phone_number.js → tz/phone_number.js} +87 -41
  82. package/esm/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  83. package/esm/src/reports/index.d.ts +2 -0
  84. package/esm/src/reports/index.d.ts.map +1 -0
  85. package/esm/src/reports/index.js +1 -0
  86. package/esm/src/reports/report_manager.d.ts +144 -0
  87. package/esm/src/reports/report_manager.d.ts.map +1 -0
  88. package/esm/src/reports/report_manager.js +315 -0
  89. package/package.json +4 -3
  90. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  91. package/script/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  92. package/script/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  93. package/script/mod.d.ts +2 -0
  94. package/script/mod.d.ts.map +1 -1
  95. package/script/mod.js +2 -0
  96. package/script/src/config/config_service.d.ts +11 -0
  97. package/script/src/config/config_service.d.ts.map +1 -0
  98. package/script/src/config/config_service.js +23 -0
  99. package/script/src/config/index.d.ts +2 -0
  100. package/script/src/config/index.d.ts.map +1 -0
  101. package/script/src/config/index.js +17 -0
  102. package/script/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  103. package/script/src/data/banks_tz.d.ts.map +1 -0
  104. package/script/src/data/countries.d.ts +6 -0
  105. package/script/src/data/countries.d.ts.map +1 -0
  106. package/script/src/data/countries.js +976 -0
  107. package/script/src/data/currencies.d.ts +1901 -0
  108. package/script/src/data/currencies.d.ts.map +1 -0
  109. package/script/src/data/currencies.js +1075 -0
  110. package/script/src/data/phone_patterns.d.ts +3809 -0
  111. package/script/src/data/phone_patterns.d.ts.map +1 -0
  112. package/script/src/data/phone_patterns.js +2327 -0
  113. package/script/src/models/amount/amount.d.ts +10 -12
  114. package/script/src/models/amount/amount.d.ts.map +1 -1
  115. package/script/src/models/amount/amount.js +60 -98
  116. package/script/src/models/bank/bank.d.ts +58 -53
  117. package/script/src/models/bank/bank.d.ts.map +1 -1
  118. package/script/src/models/bank/bank.js +49 -87
  119. package/script/src/models/bank/index.d.ts +1 -1
  120. package/script/src/models/bank/index.d.ts.map +1 -1
  121. package/script/src/models/bank/index.js +1 -1
  122. package/script/src/models/bank/service.d.ts +106 -0
  123. package/script/src/models/bank/service.d.ts.map +1 -0
  124. package/script/src/models/bank/service.js +247 -0
  125. package/script/src/models/country/country.d.ts +568 -0
  126. package/script/src/models/country/country.d.ts.map +1 -0
  127. package/script/src/models/country/country.js +169 -0
  128. package/script/src/models/country/country.test.d.ts.map +1 -0
  129. package/script/src/models/country/index.d.ts +3 -0
  130. package/script/src/models/country/index.d.ts.map +1 -0
  131. package/script/src/models/country/index.js +18 -0
  132. package/script/src/models/country/service.d.ts +75 -0
  133. package/script/src/models/country/service.d.ts.map +1 -0
  134. package/script/src/models/country/service.js +274 -0
  135. package/script/src/models/currency/currency.d.ts +341 -0
  136. package/script/src/models/currency/currency.d.ts.map +1 -0
  137. package/script/src/models/currency/currency.js +229 -0
  138. package/script/src/models/currency/currency.test.d.ts.map +1 -0
  139. package/script/src/models/currency/index.d.ts +3 -0
  140. package/script/src/models/currency/index.d.ts.map +1 -0
  141. package/script/src/models/currency/index.js +18 -0
  142. package/script/src/models/currency/service.d.ts +96 -0
  143. package/script/src/models/currency/service.d.ts.map +1 -0
  144. package/script/src/models/currency/service.js +201 -0
  145. package/script/src/models/index.d.ts +2 -0
  146. package/script/src/models/index.d.ts.map +1 -1
  147. package/script/src/models/index.js +2 -0
  148. package/script/src/models/phone_number/format.d.ts +14 -0
  149. package/script/src/models/phone_number/format.d.ts.map +1 -0
  150. package/script/src/models/phone_number/format.js +17 -0
  151. package/script/src/models/phone_number/global/phone_number.d.ts +160 -0
  152. package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  153. package/script/src/models/phone_number/global/phone_number.js +457 -0
  154. package/script/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  155. package/script/src/models/phone_number/global/service.d.ts +260 -0
  156. package/script/src/models/phone_number/global/service.d.ts.map +1 -0
  157. package/script/src/models/phone_number/global/service.js +485 -0
  158. package/script/src/models/phone_number/global/service.test.d.ts.map +1 -0
  159. package/script/src/models/phone_number/index.d.ts +5 -3
  160. package/script/src/models/phone_number/index.d.ts.map +1 -1
  161. package/script/src/models/phone_number/index.js +5 -3
  162. package/script/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  163. package/script/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  164. package/script/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +1 -1
  165. package/script/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  166. package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  167. package/{esm/src/models/phone_number → script/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  168. package/script/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  169. package/script/src/models/phone_number/{phone_number.js → tz/phone_number.js} +89 -43
  170. package/script/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  171. package/script/src/reports/index.d.ts +2 -0
  172. package/script/src/reports/index.d.ts.map +1 -0
  173. package/script/src/reports/index.js +17 -0
  174. package/script/src/reports/report_manager.d.ts +144 -0
  175. package/script/src/reports/report_manager.d.ts.map +1 -0
  176. package/script/src/reports/report_manager.js +325 -0
  177. package/esm/src/models/bank/banks.d.ts.map +0 -1
  178. package/esm/src/models/bank/utils.d.ts +0 -25
  179. package/esm/src/models/bank/utils.d.ts.map +0 -1
  180. package/esm/src/models/bank/utils.js +0 -35
  181. package/esm/src/models/phone_number/antd_validator.d.ts.map +0 -1
  182. package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  183. package/esm/src/models/phone_number/network_operator.d.ts.map +0 -1
  184. package/esm/src/models/phone_number/phone_number.d.ts.map +0 -1
  185. package/esm/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  186. package/script/src/models/bank/banks.d.ts.map +0 -1
  187. package/script/src/models/bank/utils.d.ts +0 -25
  188. package/script/src/models/bank/utils.d.ts.map +0 -1
  189. package/script/src/models/bank/utils.js +0 -41
  190. package/script/src/models/phone_number/antd_validator.d.ts.map +0 -1
  191. package/script/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  192. package/script/src/models/phone_number/network_operator.d.ts.map +0 -1
  193. package/script/src/models/phone_number/phone_number.d.ts.map +0 -1
  194. package/script/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  195. /package/esm/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  196. /package/esm/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  197. /package/esm/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
  198. /package/script/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  199. /package/script/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  200. /package/script/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Country = void 0;
4
+ const service_js_1 = require("./service.js");
5
+ /**
6
+ * Represents a country with essential details.
7
+ * @class Country
8
+ */
9
+ class Country {
10
+ /**
11
+ * Creates a new Country instance.
12
+ * @param {string} _name - The full name of the country
13
+ * @param {string} _code - The ISO country code
14
+ */
15
+ constructor(_name, _code) {
16
+ Object.defineProperty(this, "_name", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: _name
21
+ });
22
+ Object.defineProperty(this, "_code", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: _code
27
+ });
28
+ }
29
+ /**
30
+ * Gets the full name of the country.
31
+ * @returns {string} The full name of the country
32
+ */
33
+ get name() {
34
+ return this._name;
35
+ }
36
+ /**
37
+ * Gets the ISO code of the country.
38
+ * @returns {string} The ISO code of the country
39
+ */
40
+ get code() {
41
+ return this._code;
42
+ }
43
+ /**
44
+ * Creates a string representation of the country.
45
+ * @returns {string} String representation of the country
46
+ */
47
+ toString() {
48
+ return `${this.name} (${this.code})`;
49
+ }
50
+ /**
51
+ * Retrieves a country by its ISO code.
52
+ * @param {string} code The ISO code of the country.
53
+ * @returns {Country | undefined} The country corresponding to the ISO code or `undefined` if not found.
54
+ */
55
+ static fromCode(code) {
56
+ return service_js_1.CountryService.getInstance().fromCode(code);
57
+ }
58
+ /**
59
+ * Retrieves a country by its name.
60
+ * @param {string} countryName The name of the country.
61
+ * @returns {Country | undefined} The country corresponding to the name or `undefined` if not found.
62
+ */
63
+ static fromName(countryName) {
64
+ return service_js_1.CountryService.getInstance().fromName(countryName);
65
+ }
66
+ /**
67
+ * Returns all available countries.
68
+ * @returns {Country[]} Array of all countries
69
+ */
70
+ static getAll() {
71
+ return service_js_1.CountryService.getInstance().getAll();
72
+ }
73
+ /**
74
+ * Validates if a given ISO country code is valid
75
+ * @param code The country code to validate
76
+ * @returns True if the country code is valid
77
+ */
78
+ static isValidCode(code) {
79
+ if (!code)
80
+ return false;
81
+ const country = Country.fromCode(code);
82
+ return !!country;
83
+ }
84
+ /**
85
+ * Validates if a given country name is valid
86
+ * @param countryName The country name to validate
87
+ * @returns True if the country name is valid
88
+ */
89
+ static isValidName(countryName) {
90
+ if (!countryName)
91
+ return false;
92
+ const country = Country.fromName(countryName);
93
+ return !!country;
94
+ }
95
+ /**
96
+ * Checks the validity of the country data
97
+ * @returns true if the country information is available and valid
98
+ */
99
+ validate() {
100
+ try {
101
+ return (Country.fromName(this._name) !== undefined &&
102
+ Country.fromCode(this._code) !== undefined);
103
+ }
104
+ catch (_) {
105
+ return false;
106
+ }
107
+ }
108
+ /**
109
+ * Attempts to create a Country instance from a country name or ISO code
110
+ * @param input The country name or ISO code
111
+ * @returns A Country instance if valid input, undefined otherwise
112
+ */
113
+ static from(input) {
114
+ if (Country.canConstruct(input)) {
115
+ const country1 = Country.fromName(input);
116
+ if (country1)
117
+ return country1;
118
+ const country2 = Country.fromCode(input);
119
+ if (country2)
120
+ return country2;
121
+ }
122
+ return undefined;
123
+ }
124
+ /**
125
+ * Validates if the input can be used to construct a valid Country instance
126
+ * @param input The country name or ISO code to validate
127
+ * @returns True if input can construct a valid country, false otherwise
128
+ */
129
+ static canConstruct(input) {
130
+ if (!input || typeof input !== "string")
131
+ return false;
132
+ const text = input.trim();
133
+ if (text.length === 0)
134
+ return false;
135
+ const countryFromCode = Country.fromCode(text);
136
+ const countryFromName = Country.fromName(text);
137
+ return countryFromCode !== undefined || countryFromName !== undefined;
138
+ }
139
+ /**
140
+ * Checks if an unknown value is a Country instance
141
+ * @param obj The value to validate
142
+ * @returns Type predicate indicating if the value is a valid Country
143
+ */
144
+ static is(obj) {
145
+ if (!obj || typeof obj !== "object")
146
+ return false;
147
+ const maybeCountry = obj;
148
+ // Check private properties exist with correct types
149
+ if (typeof maybeCountry._name !== "string")
150
+ return false;
151
+ if (typeof maybeCountry._code !== "string")
152
+ return false;
153
+ // Validate against known countries
154
+ const countryFromCode = Country.from(maybeCountry._code);
155
+ const countryFromName = Country.from(maybeCountry._name);
156
+ return Boolean(countryFromCode &&
157
+ countryFromName &&
158
+ countryFromCode.code === countryFromName.code);
159
+ }
160
+ }
161
+ exports.Country = Country;
162
+ // Initialize static properties by applying the references from CountryService
163
+ (function setupStaticReferences() {
164
+ const staticRefs = service_js_1.CountryService.getInstance().getStaticReferences();
165
+ staticRefs.forEach((country, key) => {
166
+ // deno-lint-ignore no-explicit-any
167
+ Country[key] = country;
168
+ });
169
+ })();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"country.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/country/country.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from "./country.js";
2
+ export * from "./service.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/country/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./country.js"), exports);
18
+ __exportStar(require("./service.js"), exports);
@@ -0,0 +1,75 @@
1
+ import { Country } from "./country.js";
2
+ /**
3
+ * Service for managing country data.
4
+ * @class CountryService
5
+ */
6
+ export declare class CountryService {
7
+ private static instance;
8
+ private countryList;
9
+ private codeRecord;
10
+ private nameRecord;
11
+ private fullNameRecord;
12
+ private staticReferences;
13
+ private constructor();
14
+ /**
15
+ * Gets the singleton instance of CountryService.
16
+ * Creates the instance if it doesn't exist.
17
+ * @static
18
+ * @returns {CountryService} The singleton instance
19
+ */
20
+ static getInstance(): CountryService;
21
+ /**
22
+ * Initializes the service with country data.
23
+ * Should be called once when your application starts.
24
+ */
25
+ private initialize;
26
+ /**
27
+ * Gets all countries.
28
+ * @returns {Country[]} Array of all countries
29
+ */
30
+ getAll(): Country[];
31
+ /**
32
+ * Gets all countries as a record.
33
+ * @returns {Record<string, Country>} Record of country codes and country objects
34
+ */
35
+ getAllAsRecord(): Record<string, Country>;
36
+ /**
37
+ * Gets static country references to be used by the Country class.
38
+ * @returns {Map<string, Country>} Map of static references
39
+ */
40
+ getStaticReferences(): Map<string, Country>;
41
+ /**
42
+ * Gets the full name record mapping.
43
+ * @returns {Record<string, Country>} Record of uppercase full name keys to country objects
44
+ */
45
+ getFullNameRecord(): Record<string, Country>;
46
+ /**
47
+ * Retrieves a country by its ISO code.
48
+ * @param {string} code The ISO code of the country.
49
+ * @returns {Country | undefined} The country corresponding to the ISO code or `undefined` if not found.
50
+ */
51
+ fromCode(code: string): Country | undefined;
52
+ /**
53
+ * Retrieves a country by its name.
54
+ * @param {string} countryName The name of the country.
55
+ * @returns {Country | undefined} The country corresponding to the name or `undefined` if not found.
56
+ */
57
+ fromName(countryName: string): Country | undefined;
58
+ /**
59
+ * Searches for countries that match the given search term.
60
+ * @param {string} searchTerm - The partial name or code to search for.
61
+ * @param {number} [limit=10] - Maximum number of results to return.
62
+ * @returns {Country[]} Array of matching countries, limited to specified count.
63
+ */
64
+ search(searchTerm: string, limit?: number): Country[];
65
+ /**
66
+ * Compares two Country instances for equality by checking their name and code
67
+ *
68
+ * @param {Country} country1 - First country to compare
69
+ * @param {Country} country2 - Second country to compare
70
+ * @returns {boolean} True if countries are equal, false otherwise
71
+ * @private
72
+ */
73
+ compare(country1: Country, country2: Country): boolean;
74
+ }
75
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/country/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,cAAc,CAA+B;IAGrD,OAAO,CAAC,gBAAgB,CAAmC;IAE3D,OAAO;IAEP;;;;;OAKG;IACH,MAAM,CAAC,WAAW,IAAI,cAAc;IAQpC;;;OAGG;IACH,OAAO,CAAC,UAAU;IA2JlB;;;OAGG;IACH,MAAM,IAAI,OAAO,EAAE;IAInB;;;OAGG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAIzC;;;OAGG;IACH,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAI3C;;;OAGG;IACH,iBAAiB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI5C;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAI3C;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAqBlD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,EAAE;IAczD;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO;CAMvD"}
@@ -0,0 +1,274 @@
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, "nameRecord", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: {}
32
+ });
33
+ Object.defineProperty(this, "fullNameRecord", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: {}
38
+ });
39
+ // Static references for direct access through Country class
40
+ Object.defineProperty(this, "staticReferences", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: new Map()
45
+ });
46
+ }
47
+ /**
48
+ * Gets the singleton instance of CountryService.
49
+ * Creates the instance if it doesn't exist.
50
+ * @static
51
+ * @returns {CountryService} The singleton instance
52
+ */
53
+ static getInstance() {
54
+ if (!CountryService.instance) {
55
+ CountryService.instance = new CountryService();
56
+ CountryService.instance.initialize();
57
+ }
58
+ return CountryService.instance;
59
+ }
60
+ /**
61
+ * Initializes the service with country data.
62
+ * Should be called once when your application starts.
63
+ */
64
+ initialize() {
65
+ try {
66
+ const data = JSON.parse(JSON.stringify(countries_js_1.default));
67
+ const countries = Object.values(data).map((c) => new country_js_1.Country(c.name, c.code));
68
+ const code_record = {};
69
+ const name_record = {};
70
+ const fullname_record = {};
71
+ countries.forEach((country) => {
72
+ // Populate code record
73
+ code_record[country.code] = country;
74
+ // Add to record by name
75
+ name_record[country.name.toUpperCase()] = country;
76
+ // Generate uppercase full name with underscores
77
+ const fullNameKey = country.name
78
+ .toUpperCase()
79
+ .replace(/\s+/g, "_")
80
+ .replace(/[-(),.']/g, "")
81
+ .replace(/&/g, "AND");
82
+ fullname_record[fullNameKey] = country;
83
+ // Save references for static access
84
+ this.staticReferences.set(country.code.toUpperCase(), country);
85
+ this.staticReferences.set(fullNameKey, country);
86
+ });
87
+ // Ensure specific mappings are available
88
+ if (code_record["US"]) {
89
+ fullname_record["UNITED_STATES"] = code_record["US"];
90
+ this.staticReferences.set("UNITED_STATES", code_record["US"]);
91
+ }
92
+ // Add specific country mappings
93
+ // Cocos Islands
94
+ if (code_record["CC"]) {
95
+ fullname_record["COCOS_ISLANDS"] = code_record["CC"];
96
+ this.staticReferences.set("COCOS_ISLANDS", code_record["CC"]);
97
+ }
98
+ // Democratic Republic of Congo
99
+ if (code_record["CD"]) {
100
+ fullname_record["DEMOCRATIC_REPUBLIC_OF_CONGO"] = code_record["CD"];
101
+ this.staticReferences.set("DEMOCRATIC_REPUBLIC_OF_CONGO", code_record["CD"]);
102
+ }
103
+ // Cote d'Ivoire
104
+ if (code_record["CI"]) {
105
+ fullname_record["COTE_DIVOIRE"] = code_record["CI"];
106
+ this.staticReferences.set("COTE_DIVOIRE", code_record["CI"]);
107
+ }
108
+ // Falkland Islands
109
+ if (code_record["FK"]) {
110
+ fullname_record["FALKLAND_ISLANDS"] = code_record["FK"];
111
+ this.staticReferences.set("FALKLAND_ISLANDS", code_record["FK"]);
112
+ }
113
+ // Holy See (Vatican)
114
+ if (code_record["VA"]) {
115
+ fullname_record["HOLY_SEE"] = code_record["VA"];
116
+ this.staticReferences.set("HOLY_SEE", code_record["VA"]);
117
+ }
118
+ // Iran
119
+ if (code_record["IR"]) {
120
+ fullname_record["IRAN"] = code_record["IR"];
121
+ this.staticReferences.set("IRAN", code_record["IR"]);
122
+ }
123
+ // North Korea
124
+ if (code_record["KP"]) {
125
+ fullname_record["NORTH_KOREA"] = code_record["KP"];
126
+ this.staticReferences.set("NORTH_KOREA", code_record["KP"]);
127
+ }
128
+ // South Korea
129
+ if (code_record["KR"]) {
130
+ fullname_record["SOUTH_KOREA"] = code_record["KR"];
131
+ this.staticReferences.set("SOUTH_KOREA", code_record["KR"]);
132
+ }
133
+ // Lao People's Democratic Republic
134
+ if (code_record["LA"]) {
135
+ fullname_record["LAO"] = code_record["LA"];
136
+ this.staticReferences.set("LAO", code_record["LA"]);
137
+ }
138
+ // Palestine
139
+ if (code_record["PS"]) {
140
+ fullname_record["PALESTINE"] = code_record["PS"];
141
+ this.staticReferences.set("PALESTINE", code_record["PS"]);
142
+ }
143
+ // Macedonia
144
+ if (code_record["MK"]) {
145
+ fullname_record["MACEDONIA"] = code_record["MK"];
146
+ this.staticReferences.set("MACEDONIA", code_record["MK"]);
147
+ }
148
+ // Micronesia
149
+ if (code_record["FM"]) {
150
+ fullname_record["MICRONESIA"] = code_record["FM"];
151
+ this.staticReferences.set("MICRONESIA", code_record["FM"]);
152
+ }
153
+ // Moldova
154
+ if (code_record["MD"]) {
155
+ fullname_record["MOLDOVA"] = code_record["MD"];
156
+ this.staticReferences.set("MOLDOVA", code_record["MD"]);
157
+ }
158
+ // Taiwan
159
+ if (code_record["TW"]) {
160
+ fullname_record["TAIWAN"] = code_record["TW"];
161
+ this.staticReferences.set("TAIWAN", code_record["TW"]);
162
+ }
163
+ // Tanzania
164
+ if (code_record["TZ"]) {
165
+ fullname_record["TANZANIA"] = code_record["TZ"];
166
+ this.staticReferences.set("TANZANIA", code_record["TZ"]);
167
+ }
168
+ // US Virgin Islands
169
+ if (code_record["VI"]) {
170
+ fullname_record["VIRGIN_ISLANDS_US"] = code_record["VI"];
171
+ this.staticReferences.set("VIRGIN_ISLANDS_US", code_record["VI"]);
172
+ }
173
+ // British Virgin Islands
174
+ if (code_record["VG"]) {
175
+ fullname_record["VIRGIN_ISLANDS_BRITISH"] = code_record["VG"];
176
+ this.staticReferences.set("VIRGIN_ISLANDS_BRITISH", code_record["VG"]);
177
+ }
178
+ this.codeRecord = code_record;
179
+ this.nameRecord = name_record;
180
+ this.fullNameRecord = fullname_record;
181
+ this.countryList = countries;
182
+ }
183
+ catch (error) {
184
+ console.error("Failed to initialize CountryService:", error);
185
+ }
186
+ }
187
+ /**
188
+ * Gets all countries.
189
+ * @returns {Country[]} Array of all countries
190
+ */
191
+ getAll() {
192
+ return this.countryList;
193
+ }
194
+ /**
195
+ * Gets all countries as a record.
196
+ * @returns {Record<string, Country>} Record of country codes and country objects
197
+ */
198
+ getAllAsRecord() {
199
+ return this.codeRecord;
200
+ }
201
+ /**
202
+ * Gets static country references to be used by the Country class.
203
+ * @returns {Map<string, Country>} Map of static references
204
+ */
205
+ getStaticReferences() {
206
+ return this.staticReferences;
207
+ }
208
+ /**
209
+ * Gets the full name record mapping.
210
+ * @returns {Record<string, Country>} Record of uppercase full name keys to country objects
211
+ */
212
+ getFullNameRecord() {
213
+ return this.fullNameRecord;
214
+ }
215
+ /**
216
+ * Retrieves a country by its ISO code.
217
+ * @param {string} code The ISO code of the country.
218
+ * @returns {Country | undefined} The country corresponding to the ISO code or `undefined` if not found.
219
+ */
220
+ fromCode(code) {
221
+ return this.codeRecord[code.toUpperCase()];
222
+ }
223
+ /**
224
+ * Retrieves a country by its name.
225
+ * @param {string} countryName The name of the country.
226
+ * @returns {Country | undefined} The country corresponding to the name or `undefined` if not found.
227
+ */
228
+ fromName(countryName) {
229
+ // First try direct lookup in name record
230
+ const directMatch = this.nameRecord[countryName.toUpperCase()];
231
+ if (directMatch)
232
+ return directMatch;
233
+ // Then try full name record
234
+ const fullNameKey = countryName
235
+ .toUpperCase()
236
+ .replace(/\s+/g, "_")
237
+ .replace(/[-(),.']/g, "")
238
+ .replace(/&/g, "AND");
239
+ const fullNameMatch = this.fullNameRecord[fullNameKey];
240
+ if (fullNameMatch)
241
+ return fullNameMatch;
242
+ // If not found, try more lenient matching
243
+ return this.countryList.find((country) => country.name.toLowerCase() === countryName.toLowerCase());
244
+ }
245
+ /**
246
+ * Searches for countries that match the given search term.
247
+ * @param {string} searchTerm - The partial name or code to search for.
248
+ * @param {number} [limit=10] - Maximum number of results to return.
249
+ * @returns {Country[]} Array of matching countries, limited to specified count.
250
+ */
251
+ search(searchTerm, limit = 10) {
252
+ if (!searchTerm || typeof searchTerm !== "string")
253
+ return [];
254
+ const term = searchTerm.toLowerCase().trim();
255
+ if (term.length === 0)
256
+ return [];
257
+ const results = this.countryList.filter((country) => country.name.toLowerCase().includes(term) ||
258
+ country.code.toLowerCase().includes(term));
259
+ return results.slice(0, limit);
260
+ }
261
+ /**
262
+ * Compares two Country instances for equality by checking their name and code
263
+ *
264
+ * @param {Country} country1 - First country to compare
265
+ * @param {Country} country2 - Second country to compare
266
+ * @returns {boolean} True if countries are equal, false otherwise
267
+ * @private
268
+ */
269
+ compare(country1, country2) {
270
+ return (country1.name === country2.name &&
271
+ country1.code === country2.code);
272
+ }
273
+ }
274
+ exports.CountryService = CountryService;