@temboplus/frontend-core 0.2.5 → 0.2.7

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 +1 @@
1
- {"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../../src/src/models/amount/amount.ts"],"names":[],"mappings":"AAOA,QAAA,MAAM,YAAY,QAA2C,CAAC;AAE9D,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAEpC,OAAO;IAcP;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,YAAY,GAAE,MAAc,GAC3B,MAAM,GAAG,SAAS;IAkCrB;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,qBAAqB,IAAI,MAAM,CAKlC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC9B,YAAY,GAAE,MAAc,GAC3B,OAAO;IAQV;;;;;;OAMG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;IA4B7C;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B;AAgDD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../../../src/src/models/amount/amount.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,YAAY,QAA2C,CAAC;AAE9D,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IAEpC,OAAO;IAcP;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,YAAY,GAAE,MAAc,GAC3B,MAAM,GAAG,SAAS;IAkCrB;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;OAEG;IACH,IAAI,qBAAqB,IAAI,MAAM,CAKlC;IAED;;;;;OAKG;IACH,MAAM,CAAC,YAAY,CACjB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC9B,YAAY,GAAE,MAAc,GAC3B,OAAO;IAQV;;;;;;OAMG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,MAAM;IA4B7C;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B;AAgDD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC"}
@@ -3,7 +3,7 @@
3
3
  // ^(?:\d{1,3}(?:,\d{3})*|\d+) - Either grouped digits with commas OR just digits
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.AMOUNT_REGEX = exports.Amount = void 0;
6
- const service_js_1 = require("../currency/service.js");
6
+ const currency_js_1 = require("../currency/currency.js");
7
7
  // (?:\.\d+)?$ - Optional decimal part with any number of digits
8
8
  const AMOUNT_REGEX = /^(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d+)?$/;
9
9
  exports.AMOUNT_REGEX = AMOUNT_REGEX;
@@ -27,7 +27,7 @@ class Amount {
27
27
  writable: true,
28
28
  value: void 0
29
29
  });
30
- const code = service_js_1.CurrencyService.getInstance().fromCode(currencyCode);
30
+ const code = currency_js_1.CurrencyService.getInstance().fromCode(currencyCode);
31
31
  if (!code) {
32
32
  throw new Error("Invalid code!");
33
33
  }
@@ -43,7 +43,7 @@ class Amount {
43
43
  * @returns Amount instance or undefined if validation fails
44
44
  */
45
45
  static from(input, currencyCode = "TZS") {
46
- const currency = service_js_1.CurrencyService.getInstance().fromCode(currencyCode);
46
+ const currency = currency_js_1.CurrencyService.getInstance().fromCode(currencyCode);
47
47
  if (!currency)
48
48
  return undefined;
49
49
  let amountText = input.toString().trim();
@@ -167,7 +167,7 @@ exports.Amount = Amount;
167
167
  * @returns {string} A string with commas and currency symbols removed
168
168
  */
169
169
  function removeCommasAndCurrency(text) {
170
- const currencyPatterns = service_js_1.CurrencyService.getInstance()
170
+ const currencyPatterns = currency_js_1.CurrencyService.getInstance()
171
171
  .getCurrencySymbolPattern();
172
172
  const regex = new RegExp(`(?:${currencyPatterns})\\s*|\\s*(?:${currencyPatterns})`, "gi");
173
173
  return text
@@ -1,3 +1,26 @@
1
+ /**
2
+ * @fileoverview This file contains both the Bank class and BankService class.
3
+ *
4
+ * ARCHITECTURE NOTE: Bank and BankService Classes
5
+ * ===============================================
6
+ *
7
+ * These two classes have been intentionally placed in the same file to follow
8
+ * the established domain model pattern used with Country and Currency classes.
9
+ *
10
+ * - Bank class: Defines bank properties and static accessors
11
+ * - BankService class: Loads bank data and provides instance methods
12
+ *
13
+ * Benefits of this approach:
14
+ * 1. Prevents circular dependencies between the classes
15
+ * 2. Ensures static properties are immediately available on import
16
+ * 3. Maintains a consistent architectural pattern across domain models
17
+ * 4. Encapsulates all bank-related functionality in a single module
18
+ *
19
+ * This implementation follows the "Smart Models, Dumb Services" pattern where
20
+ * the Bank class provides a rich public API through static methods that delegate
21
+ * to the internal BankService. Meanwhile, BankService handles data loading and
22
+ * indexing without being directly exposed to external code.
23
+ */
1
24
  /**
2
25
  * Represents a bank with essential details.
3
26
  * @class Bank
@@ -127,4 +150,108 @@ export declare class Bank {
127
150
  */
128
151
  static is(obj: unknown): obj is Bank;
129
152
  }
153
+ /**
154
+ * Regex pattern to validate SWIFT codes.
155
+ * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
156
+ * @constant {RegExp}
157
+ */
158
+ export declare const SWIFT_CODE_REGEX: RegExp;
159
+ /**
160
+ * Service for managing bank data.
161
+ * @class BankService
162
+ */
163
+ export declare class BankService {
164
+ private static instance;
165
+ private bankList;
166
+ private bankRecord;
167
+ private banksByName;
168
+ private banksByShortName;
169
+ private staticReferences;
170
+ private constructor();
171
+ /**
172
+ * Gets the singleton instance of BankService.
173
+ * Creates the instance if it doesn't exist.
174
+ * @static
175
+ * @returns {BankService} The singleton instance
176
+ */
177
+ static getInstance(): BankService;
178
+ /**
179
+ * Initializes the service with bank data.
180
+ * Should be called once when your application starts.
181
+ */
182
+ private initialize;
183
+ /**
184
+ * Gets all banks.
185
+ * @returns {Bank[]} Array of all banks
186
+ */
187
+ getAll(): Bank[];
188
+ /**
189
+ * Gets all banks as a record.
190
+ * @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
191
+ */
192
+ getAllAsRecord(): Record<string, Bank>;
193
+ /**
194
+ * Gets static bank references to be used by the Bank class.
195
+ * @returns {Map<string, Bank>} Map of static references
196
+ */
197
+ getStaticReferences(): Map<string, Bank>;
198
+ /**
199
+ * Retrieves a bank by its SWIFT code.
200
+ * @param {string} swiftCode The SWIFT code of the bank.
201
+ * @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
202
+ */
203
+ fromSWIFTCode(swiftCode: string): Bank | undefined;
204
+ /**
205
+ * Retrieves a bank by its name.
206
+ * @param {string} bankName The name of the bank.
207
+ * @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
208
+ */
209
+ fromBankName(bankName: string): Bank | undefined;
210
+ /**
211
+ * Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
212
+ * @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
213
+ * @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
214
+ */
215
+ isValidSwiftCode(swiftCode?: string | null): boolean;
216
+ /**
217
+ * Validates if a given bank name is valid.
218
+ * @param {string | null | undefined} bankName - The bank name to validate.
219
+ * @returns {boolean} Returns true if the bank name is valid, false otherwise.
220
+ */
221
+ isValidBankName(bankName?: string | null): boolean;
222
+ /**
223
+ * Searches for banks that match the given search term.
224
+ * @param {string} searchTerm - The partial name or SWIFT code to search for.
225
+ * @param {number} [limit=10] - Maximum number of results to return.
226
+ * @returns {Bank[]} Array of matching banks, limited to specified count.
227
+ */
228
+ search(searchTerm: string, limit?: number): Bank[];
229
+ /**
230
+ * Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
231
+ *
232
+ * @param {Bank} bank1 - First bank to compare
233
+ * @param {Bank} bank2 - Second bank to compare
234
+ * @returns {boolean} True if banks are equal, false otherwise
235
+ * @private
236
+ */
237
+ compare(bank1: Bank, bank2: Bank): boolean;
238
+ /**
239
+ * Retrieves all SWIFT codes from the TZ_BANKS list.
240
+ * @returns {string[]} A list of all SWIFT codes in uppercase.
241
+ */
242
+ getAllSwiftCodes(): string[];
243
+ /**
244
+ * Checks whether a given SWIFT code is in the correct format.
245
+ * @param {string} swiftCode The SWIFT code to check.
246
+ * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
247
+ */
248
+ isValidSwiftCodeFormat(swiftCode: string): boolean;
249
+ /**
250
+ * Validates whether a given SWIFT code is correct.
251
+ * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
252
+ * @param {string} [swiftCode] The SWIFT code to validate.
253
+ * @returns {boolean} `true` if valid, otherwise `false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GG;IACH,MAAM,IAAI,IAAI,EAAE;IAIhB;;;OAGG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;IAItC;;;OAGG;IACH,mBAAmB,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;IAIxC;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAKlD;;;;OAIG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAqChD;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAKpD;;;;OAIG;IACH,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAKlD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,IAAI,EAAE;IAetD;;;;;;;OAOG;IACH,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO;IAQ1C;;;OAGG;IACH,gBAAgB,IAAI,MAAM,EAAE;IAI5B;;;;OAIG;IACH,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIlD;;;;;OAKG;IACH,iBAAiB,eAAgB,MAAM,KAAG,OAAO,CAQ/C;CACH"}
@@ -1,7 +1,33 @@
1
1
  "use strict";
2
+ /**
3
+ * @fileoverview This file contains both the Bank class and BankService class.
4
+ *
5
+ * ARCHITECTURE NOTE: Bank and BankService Classes
6
+ * ===============================================
7
+ *
8
+ * These two classes have been intentionally placed in the same file to follow
9
+ * the established domain model pattern used with Country and Currency classes.
10
+ *
11
+ * - Bank class: Defines bank properties and static accessors
12
+ * - BankService class: Loads bank data and provides instance methods
13
+ *
14
+ * Benefits of this approach:
15
+ * 1. Prevents circular dependencies between the classes
16
+ * 2. Ensures static properties are immediately available on import
17
+ * 3. Maintains a consistent architectural pattern across domain models
18
+ * 4. Encapsulates all bank-related functionality in a single module
19
+ *
20
+ * This implementation follows the "Smart Models, Dumb Services" pattern where
21
+ * the Bank class provides a rich public API through static methods that delegate
22
+ * to the internal BankService. Meanwhile, BankService handles data loading and
23
+ * indexing without being directly exposed to external code.
24
+ */
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Bank = void 0;
4
- const service_js_1 = require("./service.js");
29
+ exports.BankService = exports.SWIFT_CODE_REGEX = exports.Bank = void 0;
30
+ const banks_tz_js_1 = __importDefault(require("../../data/banks_tz.js"));
5
31
  /**
6
32
  * Represents a bank with essential details.
7
33
  * @class Bank
@@ -74,7 +100,7 @@ class Bank {
74
100
  * @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
75
101
  */
76
102
  static fromSWIFTCode(swiftCode) {
77
- return service_js_1.BankService.getInstance().fromSWIFTCode(swiftCode);
103
+ return BankService.getInstance().fromSWIFTCode(swiftCode);
78
104
  }
79
105
  /**
80
106
  * Retrieves a bank by its short or full name.
@@ -82,14 +108,14 @@ class Bank {
82
108
  * @returns {Bank | undefined} The bank corresponding to the full name or `undefined` if not found.
83
109
  */
84
110
  static fromBankName(bankName) {
85
- return service_js_1.BankService.getInstance().fromBankName(bankName);
111
+ return BankService.getInstance().fromBankName(bankName);
86
112
  }
87
113
  /**
88
114
  * Returns all available banks.
89
115
  * @returns {Bank[]} Array of all banks
90
116
  */
91
117
  static getAll() {
92
- return service_js_1.BankService.getInstance().getAll();
118
+ return BankService.getInstance().getAll();
93
119
  }
94
120
  /**
95
121
  * Validates if a given SWIFT/BIC (Bank Identifier Code) is valid
@@ -180,13 +206,248 @@ class Bank {
180
206
  }
181
207
  }
182
208
  exports.Bank = Bank;
183
- // Initialize static properties by applying the references from BankService.
184
- // zero-timeout to defer the initialization until after both modules have been fully loaded.
185
- // The setTimeout pushes the initialization code to the end of the JavaScript event loop,
186
- // which happens after all modules are loaded.
187
- setTimeout(() => {
209
+ /**
210
+ * Regex pattern to validate SWIFT codes.
211
+ * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
212
+ * @constant {RegExp}
213
+ */
214
+ exports.SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
215
+ /**
216
+ * Service for managing bank data.
217
+ * @class BankService
218
+ */
219
+ class BankService {
220
+ constructor() {
221
+ Object.defineProperty(this, "bankList", {
222
+ enumerable: true,
223
+ configurable: true,
224
+ writable: true,
225
+ value: []
226
+ });
227
+ Object.defineProperty(this, "bankRecord", {
228
+ enumerable: true,
229
+ configurable: true,
230
+ writable: true,
231
+ value: {}
232
+ });
233
+ Object.defineProperty(this, "banksByName", {
234
+ enumerable: true,
235
+ configurable: true,
236
+ writable: true,
237
+ value: {}
238
+ });
239
+ Object.defineProperty(this, "banksByShortName", {
240
+ enumerable: true,
241
+ configurable: true,
242
+ writable: true,
243
+ value: {}
244
+ });
245
+ // Static references for direct access through Bank class
246
+ Object.defineProperty(this, "staticReferences", {
247
+ enumerable: true,
248
+ configurable: true,
249
+ writable: true,
250
+ value: new Map()
251
+ });
252
+ /**
253
+ * Validates whether a given SWIFT code is correct.
254
+ * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
255
+ * @param {string} [swiftCode] The SWIFT code to validate.
256
+ * @returns {boolean} `true` if valid, otherwise `false`.
257
+ */
258
+ Object.defineProperty(this, "validateSWIFTCode", {
259
+ enumerable: true,
260
+ configurable: true,
261
+ writable: true,
262
+ value: (swiftCode) => {
263
+ if (!swiftCode)
264
+ return false;
265
+ const normalizedCode = swiftCode.trim().toUpperCase();
266
+ return (this.isValidSwiftCodeFormat(normalizedCode) &&
267
+ this.getAllSwiftCodes().includes(normalizedCode));
268
+ }
269
+ });
270
+ }
271
+ /**
272
+ * Gets the singleton instance of BankService.
273
+ * Creates the instance if it doesn't exist.
274
+ * @static
275
+ * @returns {BankService} The singleton instance
276
+ */
277
+ static getInstance() {
278
+ if (!BankService.instance) {
279
+ BankService.instance = new BankService();
280
+ BankService.instance.initialize();
281
+ }
282
+ return BankService.instance;
283
+ }
284
+ /**
285
+ * Initializes the service with bank data.
286
+ * Should be called once when your application starts.
287
+ */
288
+ initialize() {
289
+ try {
290
+ const data = JSON.parse(JSON.stringify(banks_tz_js_1.default));
291
+ const banks = Object.values(data).map((b) => new Bank(b.fullName, b.shortName, b.swiftCode));
292
+ const swiftCodeRecord = {};
293
+ const nameRecord = {};
294
+ const shortNameRecord = {};
295
+ banks.forEach((bank) => {
296
+ // Populate records
297
+ swiftCodeRecord[bank.swiftCode.toUpperCase()] = bank;
298
+ nameRecord[bank.fullName.toUpperCase()] = bank;
299
+ shortNameRecord[bank.shortName.toUpperCase()] = bank;
300
+ // Add to static references with uppercase short name
301
+ const shortName = bank.shortName.toUpperCase();
302
+ this.staticReferences.set(shortName, bank);
303
+ // Handle bank names with spaces (like "GT BANK")
304
+ if (shortName.includes(" ")) {
305
+ const noSpaceName = shortName.replace(/\s+/g, "_");
306
+ this.staticReferences.set(noSpaceName, bank);
307
+ }
308
+ });
309
+ this.bankRecord = swiftCodeRecord;
310
+ this.banksByName = nameRecord;
311
+ this.banksByShortName = shortNameRecord;
312
+ this.bankList = banks;
313
+ }
314
+ catch (error) {
315
+ console.error("Failed to initialize BankService:", error);
316
+ }
317
+ }
318
+ /**
319
+ * Gets all banks.
320
+ * @returns {Bank[]} Array of all banks
321
+ */
322
+ getAll() {
323
+ return this.bankList;
324
+ }
325
+ /**
326
+ * Gets all banks as a record.
327
+ * @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
328
+ */
329
+ getAllAsRecord() {
330
+ return this.bankRecord;
331
+ }
332
+ /**
333
+ * Gets static bank references to be used by the Bank class.
334
+ * @returns {Map<string, Bank>} Map of static references
335
+ */
336
+ getStaticReferences() {
337
+ return this.staticReferences;
338
+ }
339
+ /**
340
+ * Retrieves a bank by its SWIFT code.
341
+ * @param {string} swiftCode The SWIFT code of the bank.
342
+ * @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
343
+ */
344
+ fromSWIFTCode(swiftCode) {
345
+ if (!swiftCode || typeof swiftCode !== "string")
346
+ return;
347
+ return this.bankRecord[swiftCode.toUpperCase()];
348
+ }
349
+ /**
350
+ * Retrieves a bank by its name.
351
+ * @param {string} bankName The name of the bank.
352
+ * @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
353
+ */
354
+ fromBankName(bankName) {
355
+ if (!bankName || typeof bankName !== "string")
356
+ return;
357
+ // First try shortname exact match
358
+ const bankByShortName = this.banksByShortName[bankName.toUpperCase()];
359
+ if (bankByShortName)
360
+ return bankByShortName;
361
+ // Next try fullname exact match
362
+ const bankByName = this.banksByName[bankName.toUpperCase()];
363
+ if (bankByName)
364
+ return bankByName;
365
+ // If not found, try more lenient matching on full name
366
+ for (const [name, bankObj] of Object.entries(this.banksByName)) {
367
+ if (bankName.toUpperCase() === name.toUpperCase()) {
368
+ return bankObj;
369
+ }
370
+ }
371
+ // Try lenient matching on short name
372
+ for (const [shortName, bankObj] of Object.entries(this.banksByShortName)) {
373
+ if (bankName.toUpperCase() === shortName.toUpperCase()) {
374
+ return bankObj;
375
+ }
376
+ }
377
+ // Legacy fallback - case insensitive exact match
378
+ return this.bankList.find((bank) => bank.fullName.toLowerCase() === bankName.toLowerCase() ||
379
+ bankName.toLowerCase() === bank.shortName.toLowerCase());
380
+ }
381
+ /**
382
+ * Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
383
+ * @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
384
+ * @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
385
+ */
386
+ isValidSwiftCode(swiftCode) {
387
+ if (!swiftCode)
388
+ return false;
389
+ return !!this.fromSWIFTCode(swiftCode);
390
+ }
391
+ /**
392
+ * Validates if a given bank name is valid.
393
+ * @param {string | null | undefined} bankName - The bank name to validate.
394
+ * @returns {boolean} Returns true if the bank name is valid, false otherwise.
395
+ */
396
+ isValidBankName(bankName) {
397
+ if (!bankName)
398
+ return false;
399
+ return !!this.fromBankName(bankName);
400
+ }
401
+ /**
402
+ * Searches for banks that match the given search term.
403
+ * @param {string} searchTerm - The partial name or SWIFT code to search for.
404
+ * @param {number} [limit=10] - Maximum number of results to return.
405
+ * @returns {Bank[]} Array of matching banks, limited to specified count.
406
+ */
407
+ search(searchTerm, limit = 10) {
408
+ if (!searchTerm || typeof searchTerm !== "string")
409
+ return [];
410
+ const term = searchTerm.toLowerCase().trim();
411
+ if (term.length === 0)
412
+ return [];
413
+ const results = this.bankList.filter((bank) => bank.fullName.toLowerCase().includes(term) ||
414
+ bank.shortName.toLowerCase().includes(term) ||
415
+ bank.swiftCode.toLowerCase().includes(term));
416
+ return results.slice(0, limit);
417
+ }
418
+ /**
419
+ * Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
420
+ *
421
+ * @param {Bank} bank1 - First bank to compare
422
+ * @param {Bank} bank2 - Second bank to compare
423
+ * @returns {boolean} True if banks are equal, false otherwise
424
+ * @private
425
+ */
426
+ compare(bank1, bank2) {
427
+ return (bank1.fullName === bank2.fullName &&
428
+ bank1.shortName === bank2.shortName &&
429
+ bank1.swiftCode === bank2.swiftCode);
430
+ }
431
+ /**
432
+ * Retrieves all SWIFT codes from the TZ_BANKS list.
433
+ * @returns {string[]} A list of all SWIFT codes in uppercase.
434
+ */
435
+ getAllSwiftCodes() {
436
+ return this.bankList.map((bank) => bank.swiftCode.toUpperCase());
437
+ }
438
+ /**
439
+ * Checks whether a given SWIFT code is in the correct format.
440
+ * @param {string} swiftCode The SWIFT code to check.
441
+ * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
442
+ */
443
+ isValidSwiftCodeFormat(swiftCode) {
444
+ return exports.SWIFT_CODE_REGEX.test(swiftCode);
445
+ }
446
+ }
447
+ exports.BankService = BankService;
448
+ (function setupStaticReferences() {
188
449
  try {
189
- const staticRefs = service_js_1.BankService.getInstance().getStaticReferences();
450
+ const staticRefs = BankService.getInstance().getStaticReferences();
190
451
  staticRefs.forEach((bank, key) => {
191
452
  // deno-lint-ignore no-explicit-any
192
453
  Bank[key] = bank;
@@ -195,4 +456,4 @@ setTimeout(() => {
195
456
  catch (error) {
196
457
  console.error("Failed to initialize Bank static properties:", error);
197
458
  }
198
- }, 0);
459
+ })();
@@ -1,4 +1,3 @@
1
1
  export * from "./bank.js";
2
2
  export * from "./antd_validator.js";
3
- export * from "./service.js";
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC"}
@@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./bank.js"), exports);
18
18
  __exportStar(require("./antd_validator.js"), exports);
19
- __exportStar(require("./service.js"), exports);