@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.
- package/README.md +63 -14
- package/esm/src/data/countries.d.ts +12 -2
- package/esm/src/data/countries.js +496 -248
- 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 +162 -24
- package/esm/src/models/country/country.d.ts.map +1 -1
- package/esm/src/models/country/country.js +442 -42
- 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 +12 -2
- package/script/src/data/countries.js +496 -248
- 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 +162 -24
- package/script/src/models/country/country.d.ts.map +1 -1
- package/script/src/models/country/country.js +453 -49
- 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 -111
- package/esm/src/models/country/service.d.ts.map +0 -1
- package/esm/src/models/country/service.js +0 -366
- 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 -111
- package/script/src/models/country/service.d.ts.map +0 -1
- package/script/src/models/country/service.js +0 -373
- 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/currency/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/currency/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./currency.js"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./types.js"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Type definitions for ISO currency codes
|
|
3
|
+
*
|
|
4
|
+
* These types provide type-safe representations of standard ISO codes:
|
|
5
|
+
* - CurrencyCode: ISO 4217 currency codes
|
|
6
|
+
*
|
|
7
|
+
* Benefits:
|
|
8
|
+
* - Type-safety at compile time
|
|
9
|
+
* - Zero runtime overhead (compile away to strings)
|
|
10
|
+
* - Autocompletion in modern IDEs
|
|
11
|
+
* - Protection against typos and invalid values
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* ISO 4217 currency codes
|
|
15
|
+
*
|
|
16
|
+
* These three-letter codes represent currencies based on the ISO 4217 standard.
|
|
17
|
+
* Example: "USD" for US Dollar, "EUR" for Euro, "JPY" for Japanese Yen
|
|
18
|
+
*/
|
|
19
|
+
export type CurrencyCode = "USD" | "CAD" | "EUR" | "AED" | "AFN" | "ALL" | "AMD" | "ARS" | "AUD" | "AZN" | "BAM" | "BDT" | "BGN" | "BHD" | "BIF" | "BND" | "BOB" | "BRL" | "BWP" | "BYN" | "BZD" | "CDF" | "CHF" | "CLP" | "CNY" | "COP" | "CRC" | "CVE" | "CZK" | "DJF" | "DKK" | "DOP" | "DZD" | "EEK" | "EGP" | "ERN" | "ETB" | "GBP" | "GEL" | "GHS" | "GNF" | "GTQ" | "HKD" | "HNL" | "HRK" | "HUF" | "IDR" | "ILS" | "INR" | "IQD" | "IRR" | "ISK" | "JMD" | "JOD" | "JPY" | "KES" | "KHR" | "KMF" | "KRW" | "KWD" | "KZT" | "LBP" | "LKR" | "LTL" | "LVL" | "LYD" | "MAD" | "MDL" | "MGA" | "MKD" | "MMK" | "MOP" | "MUR" | "MXN" | "MYR" | "MZN" | "NAD" | "NGN" | "NIO" | "NOK" | "NPR" | "NZD" | "OMR" | "PAB" | "PEN" | "PHP" | "PKR" | "PLN" | "PYG" | "QAR" | "RON" | "RSD" | "RUB" | "RWF" | "SAR" | "SDG" | "SEK" | "SGD" | "SOS" | "SYP" | "THB" | "TND" | "TOP" | "TRY" | "TTD" | "TWD" | "TZS" | "UAH" | "UGX" | "UYU" | "UZS" | "VEF" | "VND" | "XAF" | "XOF" | "YER" | "ZAR" | "ZMK" | "ZWL";
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/src/models/currency/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACpB,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GACrE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,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|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Type definitions for ISO currency codes
|
|
4
|
+
*
|
|
5
|
+
* These types provide type-safe representations of standard ISO codes:
|
|
6
|
+
* - CurrencyCode: ISO 4217 currency codes
|
|
7
|
+
*
|
|
8
|
+
* Benefits:
|
|
9
|
+
* - Type-safety at compile time
|
|
10
|
+
* - Zero runtime overhead (compile away to strings)
|
|
11
|
+
* - Autocompletion in modern IDEs
|
|
12
|
+
* - Protection against typos and invalid values
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { Country } from "../../country/country.js";
|
|
18
18
|
import { PhoneNumberFormat } from "../format.js";
|
|
19
|
+
import type { CountryCode, ISO2CountryCode } from "../../country/types.js";
|
|
19
20
|
/**
|
|
20
21
|
* Options for parsing phone numbers
|
|
21
22
|
*/
|
|
@@ -24,7 +25,7 @@ export interface PhoneNumberParseOptions {
|
|
|
24
25
|
* Default country to use when a dial code is shared by multiple countries
|
|
25
26
|
* This can be either a Country object or an ISO country code string
|
|
26
27
|
*/
|
|
27
|
-
defaultCountry?: Country |
|
|
28
|
+
defaultCountry?: Country | CountryCode;
|
|
28
29
|
/**
|
|
29
30
|
* Whether to throw an error when encountering an ambiguous phone number
|
|
30
31
|
* with a shared dial code
|
|
@@ -54,7 +55,7 @@ export declare class PhoneNumber {
|
|
|
54
55
|
/**
|
|
55
56
|
* Gets the country code (ISO) of the phone number
|
|
56
57
|
*/
|
|
57
|
-
get countryCode():
|
|
58
|
+
get countryCode(): ISO2CountryCode;
|
|
58
59
|
/**
|
|
59
60
|
* Gets the dial code (numeric) of the phone number
|
|
60
61
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/global/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAKnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/global/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAKnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAEvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAU;IAC1B,gEAAgE;IAChE,OAAO,CAAC,cAAc,CAAS;IAE/B;;;;;;OAMG;IACH,OAAO;IAKP;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,eAAe,CAEjC;IAED;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAKrB;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;;OAKG;IACH,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;IAoBhD;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;;OAKG;IACH,QAAQ,IAAI,OAAO;IAuCnB;;;;;;;;;OASG;WACW,IAAI,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,uBAAuB,GAChC,WAAW,GAAG,SAAS;IAsG1B;;;;;;;;;;;;;OAaG;WACW,eAAe,CAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,WAAW,GAAG,SAAS;IA0D1B;;;;;;OAMG;WACW,YAAY,CACxB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO;IAsBV;;;;;;OAMG;WACW,uBAAuB,CACnC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,EACrB,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,GACvB,OAAO;IAaV;;;;;OAKG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IA2BlD;;;;;;;;;OASG;WACW,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,GAAG,SAAS;CAwDvB"}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { Country } from "../../country/country.js";
|
|
13
13
|
import { PhoneNumber } from "./phone_number.js";
|
|
14
14
|
import { PhoneNumberFormat } from "../format.js";
|
|
15
|
+
import type { ISO2CountryCode } from "../../country/types.js";
|
|
15
16
|
/**
|
|
16
17
|
* Complete metadata for a country's phone number system
|
|
17
18
|
*/
|
|
@@ -43,11 +44,9 @@ export interface CountryMetadata {
|
|
|
43
44
|
_source: string;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
|
-
* Mapping of ISO country codes to their phone metadata
|
|
47
|
+
* Mapping of ISO country codes to their phone metadata using a Map
|
|
47
48
|
*/
|
|
48
|
-
type CountryMetadataMap =
|
|
49
|
-
[isoCode: string]: CountryMetadata;
|
|
50
|
-
};
|
|
49
|
+
type CountryMetadataMap = Map<ISO2CountryCode, CountryMetadata>;
|
|
51
50
|
/**
|
|
52
51
|
* Phone number pattern type
|
|
53
52
|
*/
|
|
@@ -74,7 +73,7 @@ export interface DialCodeInfo {
|
|
|
74
73
|
/** The national number (without the dial code) */
|
|
75
74
|
nationalNumber: string;
|
|
76
75
|
/** List of country codes that use this dial code */
|
|
77
|
-
possibleCountries:
|
|
76
|
+
possibleCountries: ISO2CountryCode[];
|
|
78
77
|
}
|
|
79
78
|
/**
|
|
80
79
|
* Error thrown when a phone number has an ambiguous country due to shared dial code
|
|
@@ -83,14 +82,14 @@ export declare class SharedDialCodeError extends Error {
|
|
|
83
82
|
/** The dial code that's shared */
|
|
84
83
|
dialCode: string;
|
|
85
84
|
/** List of country codes that share this dial code */
|
|
86
|
-
countries:
|
|
85
|
+
countries: ISO2CountryCode[];
|
|
87
86
|
/**
|
|
88
87
|
* Creates a new SharedDialCodeError
|
|
89
88
|
*
|
|
90
89
|
* @param dialCode - The shared dial code
|
|
91
90
|
* @param countries - Countries that share this dial code
|
|
92
91
|
*/
|
|
93
|
-
constructor(dialCode: string, countries:
|
|
92
|
+
constructor(dialCode: string, countries: ISO2CountryCode[]);
|
|
94
93
|
}
|
|
95
94
|
/**
|
|
96
95
|
* Service for managing global phone number operations
|
|
@@ -119,14 +118,14 @@ export declare class GlobalPhoneNumberService {
|
|
|
119
118
|
/**
|
|
120
119
|
* Gets the metadata for a specific country
|
|
121
120
|
*
|
|
122
|
-
* @param {
|
|
121
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
123
122
|
* @returns {CountryMetadata | undefined} The country metadata or undefined if not found
|
|
124
123
|
*/
|
|
125
|
-
getCountryMetadata(countryCode:
|
|
124
|
+
getCountryMetadata(countryCode: ISO2CountryCode): CountryMetadata | undefined;
|
|
126
125
|
/**
|
|
127
126
|
* Gets all country metadata
|
|
128
127
|
*
|
|
129
|
-
* @returns {CountryMetadataMap} All country metadata
|
|
128
|
+
* @returns {CountryMetadataMap} All country metadata (as a Map)
|
|
130
129
|
*/
|
|
131
130
|
getAllCountryMetadata(): CountryMetadataMap;
|
|
132
131
|
/**
|
|
@@ -149,7 +148,7 @@ export declare class GlobalPhoneNumberService {
|
|
|
149
148
|
* @param dialCode - The dial code to look up
|
|
150
149
|
* @returns The country code or undefined if not found
|
|
151
150
|
*/
|
|
152
|
-
getCountryForDialCode(dialCode: string):
|
|
151
|
+
getCountryForDialCode(dialCode: string): ISO2CountryCode | undefined;
|
|
153
152
|
/**
|
|
154
153
|
* Extracts dial code information from a phone number
|
|
155
154
|
*
|
|
@@ -167,21 +166,22 @@ export declare class GlobalPhoneNumberService {
|
|
|
167
166
|
/**
|
|
168
167
|
* Determines the most likely type of a phone number
|
|
169
168
|
*
|
|
170
|
-
* @param {
|
|
169
|
+
* @param {ISO2CountryCode} countryCode - ISO country code
|
|
171
170
|
* @param {string} nationalNumber - The national number to check
|
|
172
171
|
* @returns {PhoneNumberType} The type of the phone number
|
|
173
172
|
*/
|
|
174
|
-
getNumberType(countryCode:
|
|
173
|
+
getNumberType(countryCode: ISO2CountryCode, nationalNumber: string): PhoneNumberType;
|
|
175
174
|
/**
|
|
176
175
|
* Validates a phone number against country-specific patterns
|
|
177
176
|
*
|
|
178
|
-
* @param {
|
|
177
|
+
* @param {ISO2CountryCode} countryCode - ISO country code
|
|
179
178
|
* @param {string} nationalNumber - The national number to validate
|
|
180
179
|
* @returns {boolean} True if the phone number is valid, false otherwise
|
|
181
180
|
*/
|
|
182
|
-
validatePattern(countryCode:
|
|
181
|
+
validatePattern(countryCode: ISO2CountryCode, nationalNumber: string): boolean;
|
|
183
182
|
/**
|
|
184
183
|
* Formats a phone number according to the country's formatting rules
|
|
184
|
+
* (No changes needed in this method's logic)
|
|
185
185
|
*
|
|
186
186
|
* @param {string} phoneNumber - The phone number to format
|
|
187
187
|
* @param {PhoneNumberFormat} format - The desired format
|
|
@@ -190,6 +190,7 @@ export declare class GlobalPhoneNumberService {
|
|
|
190
190
|
formatNumber(phoneNumber: string, format?: PhoneNumberFormat): string;
|
|
191
191
|
/**
|
|
192
192
|
* Creates a PhoneNumber from an international format string
|
|
193
|
+
* (No changes needed in this method's logic)
|
|
193
194
|
*
|
|
194
195
|
* @param {string} phoneNumber - The phone number in international format
|
|
195
196
|
* @returns {PhoneNumber | undefined} The parsed phone number or undefined if invalid
|
|
@@ -197,14 +198,16 @@ export declare class GlobalPhoneNumberService {
|
|
|
197
198
|
parsePhoneNumber(phoneNumber: string): PhoneNumber | undefined;
|
|
198
199
|
/**
|
|
199
200
|
* Creates a PhoneNumber from a phone number with explicit country
|
|
201
|
+
* (No changes needed in this method's logic)
|
|
200
202
|
*
|
|
201
203
|
* @param {string} phoneNumber - The phone number in any format
|
|
202
204
|
* @param {Country | string} country - The country or country code
|
|
203
205
|
* @returns {PhoneNumber | undefined} The parsed phone number or undefined if invalid
|
|
204
206
|
*/
|
|
205
|
-
parsePhoneNumberWithCountry(phoneNumber: string, country: Country |
|
|
207
|
+
parsePhoneNumberWithCountry(phoneNumber: string, country: Country | ISO2CountryCode): PhoneNumber | undefined;
|
|
206
208
|
/**
|
|
207
209
|
* Extracts the information needed for dialing from one country to another
|
|
210
|
+
* (No changes needed in this method's logic)
|
|
208
211
|
*
|
|
209
212
|
* @param {string} fromCountry - ISO code of the country dialing from
|
|
210
213
|
* @param {PhoneNumber} phoneNumber - The phone number to dial
|
|
@@ -213,6 +216,7 @@ export declare class GlobalPhoneNumberService {
|
|
|
213
216
|
getDialingString(fromCountry: string, phoneNumber: PhoneNumber): string;
|
|
214
217
|
/**
|
|
215
218
|
* Cleans a phone number by removing all non-digit characters except the leading plus
|
|
219
|
+
* (No changes needed in this method's logic)
|
|
216
220
|
*
|
|
217
221
|
* @param {string} phoneNumber - The phone number to clean
|
|
218
222
|
* @returns {string} The cleaned phone number
|
|
@@ -220,6 +224,7 @@ export declare class GlobalPhoneNumberService {
|
|
|
220
224
|
cleanPhoneNumber(phoneNumber: string): string;
|
|
221
225
|
/**
|
|
222
226
|
* Extracts the country and national number from an international phone number
|
|
227
|
+
* (No changes needed in this method's logic - relies on extractDialCode which was updated)
|
|
223
228
|
*
|
|
224
229
|
* @param {string} phoneNumber - The phone number in international format
|
|
225
230
|
* @returns {[Country | undefined, string]} The country and national number
|
|
@@ -228,13 +233,14 @@ export declare class GlobalPhoneNumberService {
|
|
|
228
233
|
/**
|
|
229
234
|
* Gets a list of commonly used examples of valid phone numbers for a country
|
|
230
235
|
*
|
|
231
|
-
* @param {
|
|
236
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
232
237
|
* @returns {string[]} Array of example phone numbers
|
|
233
238
|
*/
|
|
234
|
-
getExampleNumbers(countryCode:
|
|
239
|
+
getExampleNumbers(countryCode: ISO2CountryCode): string[];
|
|
235
240
|
/**
|
|
236
241
|
* Generates an example phone number that would match a given pattern
|
|
237
242
|
* This is a simple implementation that handles basic patterns
|
|
243
|
+
* (No changes needed in this method's logic)
|
|
238
244
|
*
|
|
239
245
|
* @param pattern - The regex pattern
|
|
240
246
|
* @returns A string that would match the pattern
|
|
@@ -242,12 +248,13 @@ export declare class GlobalPhoneNumberService {
|
|
|
242
248
|
private generateExampleFromPattern;
|
|
243
249
|
/**
|
|
244
250
|
* Checks if a phone number is valid for a specific country
|
|
251
|
+
* (No changes needed in this method's logic)
|
|
245
252
|
*
|
|
246
253
|
* @param {string} phoneNumber - The phone number to validate
|
|
247
|
-
* @param {
|
|
254
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
248
255
|
* @returns {boolean} True if the phone number is valid for the country, false otherwise
|
|
249
256
|
*/
|
|
250
|
-
isValidForCountry(phoneNumber: string, countryCode:
|
|
257
|
+
isValidForCountry(phoneNumber: string, countryCode: ISO2CountryCode): boolean;
|
|
251
258
|
/**
|
|
252
259
|
* Checks if a given dial code exists in our database
|
|
253
260
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/global/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/global/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,QAAQ,EAAE;QACR,8CAA8C;QAC9C,QAAQ,EAAE,MAAM,CAAC;QACjB,4CAA4C;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,oCAAoC;QACpC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,uCAAuC;QACvC,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,sCAAsC;QACtC,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,oCAAoC;QACpC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,mCAAmC;QACnC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,+BAA+B;QAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,mCAAmC;QACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,KAAK,kBAAkB,GAAG,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;AAUhE;;GAEG;AACH,oBAAY,eAAe;IACzB,QAAQ,aAAa;IACrB,M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|
|
@@ -76,12 +76,13 @@ class GlobalPhoneNumberService {
|
|
|
76
76
|
* Private constructor to enforce singleton pattern
|
|
77
77
|
*/
|
|
78
78
|
constructor() {
|
|
79
|
+
// Use Map for countryMetadata
|
|
79
80
|
Object.defineProperty(this, "countryMetadata", {
|
|
80
81
|
enumerable: true,
|
|
81
82
|
configurable: true,
|
|
82
83
|
writable: true,
|
|
83
|
-
value:
|
|
84
|
-
});
|
|
84
|
+
value: new Map()
|
|
85
|
+
}); // <--- CHANGED
|
|
85
86
|
Object.defineProperty(this, "sharedCountryCodes", {
|
|
86
87
|
enumerable: true,
|
|
87
88
|
configurable: true,
|
|
@@ -120,13 +121,14 @@ class GlobalPhoneNumberService {
|
|
|
120
121
|
const data = JSON.parse(JSON.stringify(phone_patterns_js_1.default));
|
|
121
122
|
// Extract shared country codes
|
|
122
123
|
this.sharedCountryCodes = data._shared_country_codes || {};
|
|
123
|
-
|
|
124
|
+
// Populate the countryMetadata Map
|
|
125
|
+
const countriesMap = new Map(); // <--- CHANGED
|
|
126
|
+
Object.entries(data)
|
|
124
127
|
.filter(([key]) => !key.startsWith("_"))
|
|
125
|
-
.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.countryMetadata = countries;
|
|
128
|
+
.forEach(([key, value]) => {
|
|
129
|
+
countriesMap.set(key, value); // <--- CHANGED (using .set())
|
|
130
|
+
});
|
|
131
|
+
this.countryMetadata = countriesMap; // <--- CHANGED
|
|
130
132
|
this.initialized = true;
|
|
131
133
|
}
|
|
132
134
|
catch (error) {
|
|
@@ -136,16 +138,16 @@ class GlobalPhoneNumberService {
|
|
|
136
138
|
/**
|
|
137
139
|
* Gets the metadata for a specific country
|
|
138
140
|
*
|
|
139
|
-
* @param {
|
|
141
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
140
142
|
* @returns {CountryMetadata | undefined} The country metadata or undefined if not found
|
|
141
143
|
*/
|
|
142
144
|
getCountryMetadata(countryCode) {
|
|
143
|
-
return this.countryMetadata
|
|
145
|
+
return this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
144
146
|
}
|
|
145
147
|
/**
|
|
146
148
|
* Gets all country metadata
|
|
147
149
|
*
|
|
148
|
-
* @returns {CountryMetadataMap} All country metadata
|
|
150
|
+
* @returns {CountryMetadataMap} All country metadata (as a Map)
|
|
149
151
|
*/
|
|
150
152
|
getAllCountryMetadata() {
|
|
151
153
|
return this.countryMetadata;
|
|
@@ -158,6 +160,7 @@ class GlobalPhoneNumberService {
|
|
|
158
160
|
*/
|
|
159
161
|
getCountriesWithDialCode(dialCode) {
|
|
160
162
|
const dialCodeStr = dialCode.toString();
|
|
163
|
+
// sharedCountryCodes remains an object, access is unchanged
|
|
161
164
|
return this.sharedCountryCodes[dialCodeStr] || [];
|
|
162
165
|
}
|
|
163
166
|
/**
|
|
@@ -168,6 +171,7 @@ class GlobalPhoneNumberService {
|
|
|
168
171
|
*/
|
|
169
172
|
isSharedDialCode(dialCode) {
|
|
170
173
|
const dialCodeStr = dialCode.toString();
|
|
174
|
+
// sharedCountryCodes remains an object, access is unchanged
|
|
171
175
|
const countries = this.sharedCountryCodes[dialCodeStr];
|
|
172
176
|
return countries !== undefined && countries.length > 1;
|
|
173
177
|
}
|
|
@@ -178,9 +182,10 @@ class GlobalPhoneNumberService {
|
|
|
178
182
|
* @returns The country code or undefined if not found
|
|
179
183
|
*/
|
|
180
184
|
getCountryForDialCode(dialCode) {
|
|
181
|
-
|
|
185
|
+
// Iterate over Map entries
|
|
186
|
+
for (const [countryCode, metadata] of this.countryMetadata.entries()) { // <--- CHANGED (using .entries())
|
|
182
187
|
if (metadata.code.toString() === dialCode) {
|
|
183
|
-
return countryCode;
|
|
188
|
+
return countryCode; // No need for type assertion here
|
|
184
189
|
}
|
|
185
190
|
}
|
|
186
191
|
return undefined;
|
|
@@ -200,23 +205,24 @@ class GlobalPhoneNumberService {
|
|
|
200
205
|
for (let i = 3; i >= 1; i--) {
|
|
201
206
|
if (numberWithoutPlus.length <= i)
|
|
202
207
|
continue;
|
|
203
|
-
const
|
|
204
|
-
// Check if any country has this dial code
|
|
208
|
+
const potentialDialCode = numberWithoutPlus.substring(0, i); // Renamed for clarity
|
|
209
|
+
// Check if any country has this dial code by iterating Map values
|
|
205
210
|
let countryFound = false;
|
|
206
|
-
for (const
|
|
207
|
-
if (metadata.code.toString() ===
|
|
211
|
+
for (const metadata of this.countryMetadata.values()) { // <--- CHANGED (using .values())
|
|
212
|
+
if (metadata.code.toString() === potentialDialCode) {
|
|
208
213
|
countryFound = true;
|
|
209
214
|
break;
|
|
210
215
|
}
|
|
211
216
|
}
|
|
212
217
|
if (countryFound) {
|
|
213
|
-
const nationalNumber = numberWithoutPlus.substring(
|
|
214
|
-
const isShared = this.isSharedDialCode(
|
|
218
|
+
const nationalNumber = numberWithoutPlus.substring(potentialDialCode.length);
|
|
219
|
+
const isShared = this.isSharedDialCode(potentialDialCode);
|
|
220
|
+
// Use the existing methods which now work with the Map internally
|
|
215
221
|
const possibleCountries = isShared
|
|
216
|
-
? this.sharedCountryCodes[
|
|
217
|
-
: [this.getCountryForDialCode(
|
|
222
|
+
? this.sharedCountryCodes[potentialDialCode] // Access shared codes directly
|
|
223
|
+
: this.getCountryForDialCode(potentialDialCode) ? [this.getCountryForDialCode(potentialDialCode)] : [];
|
|
218
224
|
return {
|
|
219
|
-
dialCode,
|
|
225
|
+
dialCode: potentialDialCode,
|
|
220
226
|
isShared,
|
|
221
227
|
nationalNumber,
|
|
222
228
|
possibleCountries,
|
|
@@ -249,7 +255,7 @@ class GlobalPhoneNumberService {
|
|
|
249
255
|
/**
|
|
250
256
|
* Determines the most likely type of a phone number
|
|
251
257
|
*
|
|
252
|
-
* @param {
|
|
258
|
+
* @param {ISO2CountryCode} countryCode - ISO country code
|
|
253
259
|
* @param {string} nationalNumber - The national number to check
|
|
254
260
|
* @returns {PhoneNumberType} The type of the phone number
|
|
255
261
|
*/
|
|
@@ -257,8 +263,10 @@ class GlobalPhoneNumberService {
|
|
|
257
263
|
if (!countryCode || !nationalNumber) {
|
|
258
264
|
return PhoneNumberType.UNKNOWN;
|
|
259
265
|
}
|
|
260
|
-
|
|
261
|
-
|
|
266
|
+
// Use .get() to retrieve metadata
|
|
267
|
+
const metadata = this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
268
|
+
// Check if metadata exists after .get()
|
|
269
|
+
if (!metadata || !metadata.patterns) { // <--- ADDED Check for undefined
|
|
262
270
|
return PhoneNumberType.UNKNOWN;
|
|
263
271
|
}
|
|
264
272
|
// Verify that required patterns exist
|
|
@@ -285,7 +293,7 @@ class GlobalPhoneNumberService {
|
|
|
285
293
|
/**
|
|
286
294
|
* Validates a phone number against country-specific patterns
|
|
287
295
|
*
|
|
288
|
-
* @param {
|
|
296
|
+
* @param {ISO2CountryCode} countryCode - ISO country code
|
|
289
297
|
* @param {string} nationalNumber - The national number to validate
|
|
290
298
|
* @returns {boolean} True if the phone number is valid, false otherwise
|
|
291
299
|
*/
|
|
@@ -293,8 +301,10 @@ class GlobalPhoneNumberService {
|
|
|
293
301
|
if (!countryCode || !nationalNumber) {
|
|
294
302
|
return false;
|
|
295
303
|
}
|
|
296
|
-
|
|
297
|
-
|
|
304
|
+
// Use .get() to retrieve metadata
|
|
305
|
+
const metadata = this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
306
|
+
// Check if metadata exists after .get()
|
|
307
|
+
if (!metadata || !metadata.patterns) { // <--- ADDED Check for undefined
|
|
298
308
|
return false;
|
|
299
309
|
}
|
|
300
310
|
// Verify that required patterns exist
|
|
@@ -320,6 +330,7 @@ class GlobalPhoneNumberService {
|
|
|
320
330
|
}
|
|
321
331
|
/**
|
|
322
332
|
* Formats a phone number according to the country's formatting rules
|
|
333
|
+
* (No changes needed in this method's logic)
|
|
323
334
|
*
|
|
324
335
|
* @param {string} phoneNumber - The phone number to format
|
|
325
336
|
* @param {PhoneNumberFormat} format - The desired format
|
|
@@ -333,6 +344,7 @@ class GlobalPhoneNumberService {
|
|
|
333
344
|
}
|
|
334
345
|
/**
|
|
335
346
|
* Creates a PhoneNumber from an international format string
|
|
347
|
+
* (No changes needed in this method's logic)
|
|
336
348
|
*
|
|
337
349
|
* @param {string} phoneNumber - The phone number in international format
|
|
338
350
|
* @returns {PhoneNumber | undefined} The parsed phone number or undefined if invalid
|
|
@@ -342,6 +354,7 @@ class GlobalPhoneNumberService {
|
|
|
342
354
|
}
|
|
343
355
|
/**
|
|
344
356
|
* Creates a PhoneNumber from a phone number with explicit country
|
|
357
|
+
* (No changes needed in this method's logic)
|
|
345
358
|
*
|
|
346
359
|
* @param {string} phoneNumber - The phone number in any format
|
|
347
360
|
* @param {Country | string} country - The country or country code
|
|
@@ -357,6 +370,7 @@ class GlobalPhoneNumberService {
|
|
|
357
370
|
}
|
|
358
371
|
/**
|
|
359
372
|
* Extracts the information needed for dialing from one country to another
|
|
373
|
+
* (No changes needed in this method's logic)
|
|
360
374
|
*
|
|
361
375
|
* @param {string} fromCountry - ISO code of the country dialing from
|
|
362
376
|
* @param {PhoneNumber} phoneNumber - The phone number to dial
|
|
@@ -372,6 +386,7 @@ class GlobalPhoneNumberService {
|
|
|
372
386
|
}
|
|
373
387
|
/**
|
|
374
388
|
* Cleans a phone number by removing all non-digit characters except the leading plus
|
|
389
|
+
* (No changes needed in this method's logic)
|
|
375
390
|
*
|
|
376
391
|
* @param {string} phoneNumber - The phone number to clean
|
|
377
392
|
* @returns {string} The cleaned phone number
|
|
@@ -388,6 +403,7 @@ class GlobalPhoneNumberService {
|
|
|
388
403
|
}
|
|
389
404
|
/**
|
|
390
405
|
* Extracts the country and national number from an international phone number
|
|
406
|
+
* (No changes needed in this method's logic - relies on extractDialCode which was updated)
|
|
391
407
|
*
|
|
392
408
|
* @param {string} phoneNumber - The phone number in international format
|
|
393
409
|
* @returns {[Country | undefined, string]} The country and national number
|
|
@@ -413,25 +429,29 @@ class GlobalPhoneNumberService {
|
|
|
413
429
|
/**
|
|
414
430
|
* Gets a list of commonly used examples of valid phone numbers for a country
|
|
415
431
|
*
|
|
416
|
-
* @param {
|
|
432
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
417
433
|
* @returns {string[]} Array of example phone numbers
|
|
418
434
|
*/
|
|
419
435
|
getExampleNumbers(countryCode) {
|
|
420
|
-
|
|
436
|
+
// Use .get() to retrieve metadata
|
|
437
|
+
const metadata = this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
421
438
|
if (!metadata)
|
|
422
|
-
return [];
|
|
439
|
+
return []; // <--- ADDED Check for undefined
|
|
423
440
|
const dialCode = metadata.code;
|
|
424
441
|
const examples = [];
|
|
425
|
-
//
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
442
|
+
// Ensure patterns exist before trying to generate examples
|
|
443
|
+
if (metadata.patterns.landline) {
|
|
444
|
+
examples.push(`+${dialCode}${this.generateExampleFromPattern(metadata.patterns.landline)}`);
|
|
445
|
+
}
|
|
446
|
+
if (metadata.patterns.mobile) {
|
|
447
|
+
examples.push(`+${dialCode}${this.generateExampleFromPattern(metadata.patterns.mobile)}`);
|
|
448
|
+
}
|
|
430
449
|
return examples;
|
|
431
450
|
}
|
|
432
451
|
/**
|
|
433
452
|
* Generates an example phone number that would match a given pattern
|
|
434
453
|
* This is a simple implementation that handles basic patterns
|
|
454
|
+
* (No changes needed in this method's logic)
|
|
435
455
|
*
|
|
436
456
|
* @param pattern - The regex pattern
|
|
437
457
|
* @returns A string that would match the pattern
|
|
@@ -450,9 +470,10 @@ class GlobalPhoneNumberService {
|
|
|
450
470
|
}
|
|
451
471
|
/**
|
|
452
472
|
* Checks if a phone number is valid for a specific country
|
|
473
|
+
* (No changes needed in this method's logic)
|
|
453
474
|
*
|
|
454
475
|
* @param {string} phoneNumber - The phone number to validate
|
|
455
|
-
* @param {
|
|
476
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
456
477
|
* @returns {boolean} True if the phone number is valid for the country, false otherwise
|
|
457
478
|
*/
|
|
458
479
|
isValidForCountry(phoneNumber, countryCode) {
|
|
@@ -469,12 +490,12 @@ class GlobalPhoneNumberService {
|
|
|
469
490
|
* @returns True if the dial code exists, false otherwise
|
|
470
491
|
*/
|
|
471
492
|
hasDialCode(dialCode) {
|
|
472
|
-
// Check if it's a shared dial code
|
|
493
|
+
// Check if it's a shared dial code (access unchanged)
|
|
473
494
|
if (this.sharedCountryCodes[dialCode]?.length > 0) {
|
|
474
495
|
return true;
|
|
475
496
|
}
|
|
476
|
-
// Check if any country has this dial code
|
|
477
|
-
for (const metadata of
|
|
497
|
+
// Check if any country has this dial code by iterating Map values
|
|
498
|
+
for (const metadata of this.countryMetadata.values()) { // <--- CHANGED (using .values())
|
|
478
499
|
if (metadata.code.toString() === dialCode) {
|
|
479
500
|
return true;
|
|
480
501
|
}
|