@temboplus/frontend-core 0.2.4 → 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.
- package/README.md +74 -20
- package/esm/src/data/countries.d.ts +36 -3
- package/esm/src/data/countries.js +2475 -974
- package/esm/src/models/amount/amount.d.ts.map +1 -1
- package/esm/src/models/amount/amount.js +1 -1
- package/esm/src/models/bank/bank.d.ts +127 -0
- package/esm/src/models/bank/bank.d.ts.map +1 -1
- package/esm/src/models/bank/bank.js +264 -7
- package/esm/src/models/bank/index.d.ts +0 -1
- package/esm/src/models/bank/index.d.ts.map +1 -1
- package/esm/src/models/bank/index.js +0 -1
- package/esm/src/models/country/country.d.ts +278 -24
- package/esm/src/models/country/country.d.ts.map +1 -1
- package/esm/src/models/country/country.js +603 -31
- package/esm/src/models/country/index.d.ts +1 -1
- package/esm/src/models/country/index.d.ts.map +1 -1
- package/esm/src/models/country/index.js +1 -1
- package/esm/src/models/country/types.d.ts +53 -0
- package/esm/src/models/country/types.d.ts.map +1 -0
- package/esm/src/models/country/types.js +43 -0
- package/esm/src/models/currency/currency.d.ts +127 -4
- package/esm/src/models/currency/currency.d.ts.map +1 -1
- package/esm/src/models/currency/currency.js +229 -11
- package/esm/src/models/currency/index.d.ts +1 -1
- package/esm/src/models/currency/index.d.ts.map +1 -1
- package/esm/src/models/currency/index.js +1 -1
- package/esm/src/models/currency/types.d.ts +20 -0
- package/esm/src/models/currency/types.d.ts.map +1 -0
- package/esm/src/models/currency/types.js +13 -0
- package/esm/src/models/phone_number/global/phone_number.d.ts +3 -2
- package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -1
- package/esm/src/models/phone_number/global/service.d.ts +27 -20
- package/esm/src/models/phone_number/global/service.d.ts.map +1 -1
- package/esm/src/models/phone_number/global/service.js +61 -40
- package/package.json +1 -1
- package/script/src/data/countries.d.ts +36 -3
- package/script/src/data/countries.js +2475 -974
- package/script/src/models/amount/amount.d.ts.map +1 -1
- package/script/src/models/amount/amount.js +4 -4
- package/script/src/models/bank/bank.d.ts +127 -0
- package/script/src/models/bank/bank.d.ts.map +1 -1
- package/script/src/models/bank/bank.js +273 -12
- package/script/src/models/bank/index.d.ts +0 -1
- package/script/src/models/bank/index.d.ts.map +1 -1
- package/script/src/models/bank/index.js +0 -1
- package/script/src/models/country/country.d.ts +278 -24
- package/script/src/models/country/country.d.ts.map +1 -1
- package/script/src/models/country/country.js +611 -35
- package/script/src/models/country/index.d.ts +1 -1
- package/script/src/models/country/index.d.ts.map +1 -1
- package/script/src/models/country/index.js +1 -1
- package/script/src/models/country/types.d.ts +53 -0
- package/script/src/models/country/types.d.ts.map +1 -0
- package/script/src/models/country/types.js +46 -0
- package/script/src/models/currency/currency.d.ts +127 -4
- package/script/src/models/currency/currency.d.ts.map +1 -1
- package/script/src/models/currency/currency.js +237 -15
- package/script/src/models/currency/index.d.ts +1 -1
- package/script/src/models/currency/index.d.ts.map +1 -1
- package/script/src/models/currency/index.js +1 -1
- package/script/src/models/currency/types.d.ts +20 -0
- package/script/src/models/currency/types.d.ts.map +1 -0
- package/script/src/models/currency/types.js +14 -0
- package/script/src/models/phone_number/global/phone_number.d.ts +3 -2
- package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -1
- package/script/src/models/phone_number/global/service.d.ts +27 -20
- package/script/src/models/phone_number/global/service.d.ts.map +1 -1
- package/script/src/models/phone_number/global/service.js +61 -40
- package/esm/src/models/bank/service.d.ts +0 -106
- package/esm/src/models/bank/service.d.ts.map +0 -1
- package/esm/src/models/bank/service.js +0 -240
- package/esm/src/models/country/service.d.ts +0 -75
- package/esm/src/models/country/service.d.ts.map +0 -1
- package/esm/src/models/country/service.js +0 -267
- package/esm/src/models/currency/service.d.ts +0 -96
- package/esm/src/models/currency/service.d.ts.map +0 -1
- package/esm/src/models/currency/service.js +0 -194
- package/script/src/models/bank/service.d.ts +0 -106
- package/script/src/models/bank/service.d.ts.map +0 -1
- package/script/src/models/bank/service.js +0 -247
- package/script/src/models/country/service.d.ts +0 -75
- package/script/src/models/country/service.d.ts.map +0 -1
- package/script/src/models/country/service.js +0 -274
- package/script/src/models/currency/service.d.ts +0 -96
- package/script/src/models/currency/service.d.ts.map +0 -1
- package/script/src/models/currency/service.js +0 -201
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Bank } from "./bank.js";
|
|
2
|
-
/**
|
|
3
|
-
* Regex pattern to validate SWIFT codes.
|
|
4
|
-
* The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
|
|
5
|
-
* @constant {RegExp}
|
|
6
|
-
*/
|
|
7
|
-
export declare const SWIFT_CODE_REGEX: RegExp;
|
|
8
|
-
/**
|
|
9
|
-
* Service for managing bank data.
|
|
10
|
-
* @class BankService
|
|
11
|
-
*/
|
|
12
|
-
export declare class BankService {
|
|
13
|
-
private static instance;
|
|
14
|
-
private bankList;
|
|
15
|
-
private bankRecord;
|
|
16
|
-
private banksByName;
|
|
17
|
-
private banksByShortName;
|
|
18
|
-
private staticReferences;
|
|
19
|
-
private constructor();
|
|
20
|
-
/**
|
|
21
|
-
* Gets the singleton instance of BankService.
|
|
22
|
-
* Creates the instance if it doesn't exist.
|
|
23
|
-
* @static
|
|
24
|
-
* @returns {BankService} The singleton instance
|
|
25
|
-
*/
|
|
26
|
-
static getInstance(): BankService;
|
|
27
|
-
/**
|
|
28
|
-
* Initializes the service with bank data.
|
|
29
|
-
* Should be called once when your application starts.
|
|
30
|
-
*/
|
|
31
|
-
private initialize;
|
|
32
|
-
/**
|
|
33
|
-
* Gets all banks.
|
|
34
|
-
* @returns {Bank[]} Array of all banks
|
|
35
|
-
*/
|
|
36
|
-
getAll(): Bank[];
|
|
37
|
-
/**
|
|
38
|
-
* Gets all banks as a record.
|
|
39
|
-
* @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
|
|
40
|
-
*/
|
|
41
|
-
getAllAsRecord(): Record<string, Bank>;
|
|
42
|
-
/**
|
|
43
|
-
* Gets static bank references to be used by the Bank class.
|
|
44
|
-
* @returns {Map<string, Bank>} Map of static references
|
|
45
|
-
*/
|
|
46
|
-
getStaticReferences(): Map<string, Bank>;
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves a bank by its SWIFT code.
|
|
49
|
-
* @param {string} swiftCode The SWIFT code of the bank.
|
|
50
|
-
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
51
|
-
*/
|
|
52
|
-
fromSWIFTCode(swiftCode: string): Bank | undefined;
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves a bank by its name.
|
|
55
|
-
* @param {string} bankName The name of the bank.
|
|
56
|
-
* @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
|
|
57
|
-
*/
|
|
58
|
-
fromBankName(bankName: string): Bank | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
|
|
61
|
-
* @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
|
|
62
|
-
* @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
|
|
63
|
-
*/
|
|
64
|
-
isValidSwiftCode(swiftCode?: string | null): boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Validates if a given bank name is valid.
|
|
67
|
-
* @param {string | null | undefined} bankName - The bank name to validate.
|
|
68
|
-
* @returns {boolean} Returns true if the bank name is valid, false otherwise.
|
|
69
|
-
*/
|
|
70
|
-
isValidBankName(bankName?: string | null): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Searches for banks that match the given search term.
|
|
73
|
-
* @param {string} searchTerm - The partial name or SWIFT code to search for.
|
|
74
|
-
* @param {number} [limit=10] - Maximum number of results to return.
|
|
75
|
-
* @returns {Bank[]} Array of matching banks, limited to specified count.
|
|
76
|
-
*/
|
|
77
|
-
search(searchTerm: string, limit?: number): Bank[];
|
|
78
|
-
/**
|
|
79
|
-
* Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
|
|
80
|
-
*
|
|
81
|
-
* @param {Bank} bank1 - First bank to compare
|
|
82
|
-
* @param {Bank} bank2 - Second bank to compare
|
|
83
|
-
* @returns {boolean} True if banks are equal, false otherwise
|
|
84
|
-
* @private
|
|
85
|
-
*/
|
|
86
|
-
compare(bank1: Bank, bank2: Bank): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* Retrieves all SWIFT codes from the TZ_BANKS list.
|
|
89
|
-
* @returns {string[]} A list of all SWIFT codes in uppercase.
|
|
90
|
-
*/
|
|
91
|
-
getAllSwiftCodes(): string[];
|
|
92
|
-
/**
|
|
93
|
-
* Checks whether a given SWIFT code is in the correct format.
|
|
94
|
-
* @param {string} swiftCode The SWIFT code to check.
|
|
95
|
-
* @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
|
|
96
|
-
*/
|
|
97
|
-
isValidSwiftCodeFormat(swiftCode: string): boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Validates whether a given SWIFT code is correct.
|
|
100
|
-
* It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
|
|
101
|
-
* @param {string} [swiftCode] The SWIFT code to validate.
|
|
102
|
-
* @returns {boolean} `true` if valid, otherwise `false`.
|
|
103
|
-
*/
|
|
104
|
-
validateSWIFTCode: (swiftCode?: string) => boolean;
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,gBAAgB,CAA4B;IAGpD,OAAO,CAAC,gBAAgB,CAAgC;IAExD,OAAO;IAEP;;;;;OAKG;IACH,MAAM,CAAC,WAAW,IAAI,WAAW;IAQjC;;;OAGG;IACH,OAAO,CAAC,UAAU;IA0ClB;;;OAGG;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,247 +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.BankService = exports.SWIFT_CODE_REGEX = void 0;
|
|
7
|
-
const bank_js_1 = require("./bank.js");
|
|
8
|
-
const banks_tz_js_1 = __importDefault(require("../../data/banks_tz.js"));
|
|
9
|
-
/**
|
|
10
|
-
* Regex pattern to validate SWIFT codes.
|
|
11
|
-
* The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
|
|
12
|
-
* @constant {RegExp}
|
|
13
|
-
*/
|
|
14
|
-
exports.SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
|
|
15
|
-
/**
|
|
16
|
-
* Service for managing bank data.
|
|
17
|
-
* @class BankService
|
|
18
|
-
*/
|
|
19
|
-
class BankService {
|
|
20
|
-
constructor() {
|
|
21
|
-
Object.defineProperty(this, "bankList", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: []
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "bankRecord", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: {}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(this, "banksByName", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: {}
|
|
38
|
-
});
|
|
39
|
-
Object.defineProperty(this, "banksByShortName", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: {}
|
|
44
|
-
});
|
|
45
|
-
// Static references for direct access through Bank class
|
|
46
|
-
Object.defineProperty(this, "staticReferences", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: new Map()
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* Validates whether a given SWIFT code is correct.
|
|
54
|
-
* It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
|
|
55
|
-
* @param {string} [swiftCode] The SWIFT code to validate.
|
|
56
|
-
* @returns {boolean} `true` if valid, otherwise `false`.
|
|
57
|
-
*/
|
|
58
|
-
Object.defineProperty(this, "validateSWIFTCode", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
configurable: true,
|
|
61
|
-
writable: true,
|
|
62
|
-
value: (swiftCode) => {
|
|
63
|
-
if (!swiftCode)
|
|
64
|
-
return false;
|
|
65
|
-
const normalizedCode = swiftCode.trim().toUpperCase();
|
|
66
|
-
return (this.isValidSwiftCodeFormat(normalizedCode) &&
|
|
67
|
-
this.getAllSwiftCodes().includes(normalizedCode));
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets the singleton instance of BankService.
|
|
73
|
-
* Creates the instance if it doesn't exist.
|
|
74
|
-
* @static
|
|
75
|
-
* @returns {BankService} The singleton instance
|
|
76
|
-
*/
|
|
77
|
-
static getInstance() {
|
|
78
|
-
if (!BankService.instance) {
|
|
79
|
-
BankService.instance = new BankService();
|
|
80
|
-
BankService.instance.initialize();
|
|
81
|
-
}
|
|
82
|
-
return BankService.instance;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Initializes the service with bank data.
|
|
86
|
-
* Should be called once when your application starts.
|
|
87
|
-
*/
|
|
88
|
-
initialize() {
|
|
89
|
-
try {
|
|
90
|
-
const data = JSON.parse(JSON.stringify(banks_tz_js_1.default));
|
|
91
|
-
const banks = Object.values(data).map((b) => new bank_js_1.Bank(b.fullName, b.shortName, b.swiftCode));
|
|
92
|
-
const swiftCodeRecord = {};
|
|
93
|
-
const nameRecord = {};
|
|
94
|
-
const shortNameRecord = {};
|
|
95
|
-
banks.forEach((bank) => {
|
|
96
|
-
// Populate records
|
|
97
|
-
swiftCodeRecord[bank.swiftCode.toUpperCase()] = bank;
|
|
98
|
-
nameRecord[bank.fullName.toUpperCase()] = bank;
|
|
99
|
-
shortNameRecord[bank.shortName.toUpperCase()] = bank;
|
|
100
|
-
// Add to static references with uppercase short name
|
|
101
|
-
const shortName = bank.shortName.toUpperCase();
|
|
102
|
-
this.staticReferences.set(shortName, bank);
|
|
103
|
-
// Handle bank names with spaces (like "GT BANK")
|
|
104
|
-
if (shortName.includes(" ")) {
|
|
105
|
-
const noSpaceName = shortName.replace(/\s+/g, "_");
|
|
106
|
-
this.staticReferences.set(noSpaceName, bank);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
this.bankRecord = swiftCodeRecord;
|
|
110
|
-
this.banksByName = nameRecord;
|
|
111
|
-
this.banksByShortName = shortNameRecord;
|
|
112
|
-
this.bankList = banks;
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
console.error("Failed to initialize BankService:", error);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Gets all banks.
|
|
120
|
-
* @returns {Bank[]} Array of all banks
|
|
121
|
-
*/
|
|
122
|
-
getAll() {
|
|
123
|
-
return this.bankList;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Gets all banks as a record.
|
|
127
|
-
* @returns {Record<string, Bank>} Record of bank SWIFT codes and bank objects
|
|
128
|
-
*/
|
|
129
|
-
getAllAsRecord() {
|
|
130
|
-
return this.bankRecord;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Gets static bank references to be used by the Bank class.
|
|
134
|
-
* @returns {Map<string, Bank>} Map of static references
|
|
135
|
-
*/
|
|
136
|
-
getStaticReferences() {
|
|
137
|
-
return this.staticReferences;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Retrieves a bank by its SWIFT code.
|
|
141
|
-
* @param {string} swiftCode The SWIFT code of the bank.
|
|
142
|
-
* @returns {Bank | undefined} The bank corresponding to the SWIFT code or `undefined` if not found.
|
|
143
|
-
*/
|
|
144
|
-
fromSWIFTCode(swiftCode) {
|
|
145
|
-
if (!swiftCode || typeof swiftCode !== "string")
|
|
146
|
-
return;
|
|
147
|
-
return this.bankRecord[swiftCode.toUpperCase()];
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Retrieves a bank by its name.
|
|
151
|
-
* @param {string} bankName The name of the bank.
|
|
152
|
-
* @returns {Bank | undefined} The bank corresponding to the name or `undefined` if not found.
|
|
153
|
-
*/
|
|
154
|
-
fromBankName(bankName) {
|
|
155
|
-
if (!bankName || typeof bankName !== "string")
|
|
156
|
-
return;
|
|
157
|
-
// First try shortname exact match
|
|
158
|
-
const bankByShortName = this.banksByShortName[bankName.toUpperCase()];
|
|
159
|
-
if (bankByShortName)
|
|
160
|
-
return bankByShortName;
|
|
161
|
-
// Next try fullname exact match
|
|
162
|
-
const bankByName = this.banksByName[bankName.toUpperCase()];
|
|
163
|
-
if (bankByName)
|
|
164
|
-
return bankByName;
|
|
165
|
-
// If not found, try more lenient matching on full name
|
|
166
|
-
for (const [name, bankObj] of Object.entries(this.banksByName)) {
|
|
167
|
-
if (bankName.toUpperCase() === name.toUpperCase()) {
|
|
168
|
-
return bankObj;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
// Try lenient matching on short name
|
|
172
|
-
for (const [shortName, bankObj] of Object.entries(this.banksByShortName)) {
|
|
173
|
-
if (bankName.toUpperCase() === shortName.toUpperCase()) {
|
|
174
|
-
return bankObj;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// Legacy fallback - case insensitive exact match
|
|
178
|
-
return this.bankList.find((bank) => bank.fullName.toLowerCase() === bankName.toLowerCase() ||
|
|
179
|
-
bankName.toLowerCase() === bank.shortName.toLowerCase());
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Validates if a given SWIFT/BIC (Bank Identifier Code) is valid.
|
|
183
|
-
* @param {string | null | undefined} swiftCode - The SWIFT/BIC code to validate.
|
|
184
|
-
* @returns {boolean} Returns true if the SWIFT code is valid, false otherwise.
|
|
185
|
-
*/
|
|
186
|
-
isValidSwiftCode(swiftCode) {
|
|
187
|
-
if (!swiftCode)
|
|
188
|
-
return false;
|
|
189
|
-
return !!this.fromSWIFTCode(swiftCode);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Validates if a given bank name is valid.
|
|
193
|
-
* @param {string | null | undefined} bankName - The bank name to validate.
|
|
194
|
-
* @returns {boolean} Returns true if the bank name is valid, false otherwise.
|
|
195
|
-
*/
|
|
196
|
-
isValidBankName(bankName) {
|
|
197
|
-
if (!bankName)
|
|
198
|
-
return false;
|
|
199
|
-
return !!this.fromBankName(bankName);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Searches for banks that match the given search term.
|
|
203
|
-
* @param {string} searchTerm - The partial name or SWIFT code to search for.
|
|
204
|
-
* @param {number} [limit=10] - Maximum number of results to return.
|
|
205
|
-
* @returns {Bank[]} Array of matching banks, limited to specified count.
|
|
206
|
-
*/
|
|
207
|
-
search(searchTerm, limit = 10) {
|
|
208
|
-
if (!searchTerm || typeof searchTerm !== "string")
|
|
209
|
-
return [];
|
|
210
|
-
const term = searchTerm.toLowerCase().trim();
|
|
211
|
-
if (term.length === 0)
|
|
212
|
-
return [];
|
|
213
|
-
const results = this.bankList.filter((bank) => bank.fullName.toLowerCase().includes(term) ||
|
|
214
|
-
bank.shortName.toLowerCase().includes(term) ||
|
|
215
|
-
bank.swiftCode.toLowerCase().includes(term));
|
|
216
|
-
return results.slice(0, limit);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Compares two Bank instances for equality by checking their full name, short name, and SWIFT code
|
|
220
|
-
*
|
|
221
|
-
* @param {Bank} bank1 - First bank to compare
|
|
222
|
-
* @param {Bank} bank2 - Second bank to compare
|
|
223
|
-
* @returns {boolean} True if banks are equal, false otherwise
|
|
224
|
-
* @private
|
|
225
|
-
*/
|
|
226
|
-
compare(bank1, bank2) {
|
|
227
|
-
return (bank1.fullName === bank2.fullName &&
|
|
228
|
-
bank1.shortName === bank2.shortName &&
|
|
229
|
-
bank1.swiftCode === bank2.swiftCode);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Retrieves all SWIFT codes from the TZ_BANKS list.
|
|
233
|
-
* @returns {string[]} A list of all SWIFT codes in uppercase.
|
|
234
|
-
*/
|
|
235
|
-
getAllSwiftCodes() {
|
|
236
|
-
return this.bankList.map((bank) => bank.swiftCode.toUpperCase());
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Checks whether a given SWIFT code is in the correct format.
|
|
240
|
-
* @param {string} swiftCode The SWIFT code to check.
|
|
241
|
-
* @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
|
|
242
|
-
*/
|
|
243
|
-
isValidSwiftCodeFormat(swiftCode) {
|
|
244
|
-
return exports.SWIFT_CODE_REGEX.test(swiftCode);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
exports.BankService = BankService;
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|