@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
|
@@ -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,e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I,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIrE;;;;;;;OAOG;IACI,2BAA2B,CAChC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,GAAG,eAAe,GACjC,WAAW,GAAG,SAAS;IAU1B;;;;;;;OAOG;IACI,gBAAgB,CACrB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,GACvB,MAAM;IAUT;;;;;;OAMG;IACI,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAapD;;;;;;OAMG;IACI,YAAY,CAAC,WAAW,EAAE,MAAM,GAAG,CAAC,OAAO,GAAG,SAAS,EAAE,MAAM,CAAC;IAkBvE;;;;;OAKG;IACI,iBAAiB,CAAC,WAAW,EAAE,eAAe,GAAG,MAAM,EAAE;IA4BhE;;;;;;;OAOG;IACH,OAAO,CAAC,0BAA0B;IAgBlC;;;;;;;OAOG;IACI,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO;IAQpF;;;;;OAKG;IACI,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAe9C"}
|
|
@@ -69,12 +69,13 @@ export class GlobalPhoneNumberService {
|
|
|
69
69
|
* Private constructor to enforce singleton pattern
|
|
70
70
|
*/
|
|
71
71
|
constructor() {
|
|
72
|
+
// Use Map for countryMetadata
|
|
72
73
|
Object.defineProperty(this, "countryMetadata", {
|
|
73
74
|
enumerable: true,
|
|
74
75
|
configurable: true,
|
|
75
76
|
writable: true,
|
|
76
|
-
value:
|
|
77
|
-
});
|
|
77
|
+
value: new Map()
|
|
78
|
+
}); // <--- CHANGED
|
|
78
79
|
Object.defineProperty(this, "sharedCountryCodes", {
|
|
79
80
|
enumerable: true,
|
|
80
81
|
configurable: true,
|
|
@@ -113,13 +114,14 @@ export class GlobalPhoneNumberService {
|
|
|
113
114
|
const data = JSON.parse(JSON.stringify(phonePatterns));
|
|
114
115
|
// Extract shared country codes
|
|
115
116
|
this.sharedCountryCodes = data._shared_country_codes || {};
|
|
116
|
-
|
|
117
|
+
// Populate the countryMetadata Map
|
|
118
|
+
const countriesMap = new Map(); // <--- CHANGED
|
|
119
|
+
Object.entries(data)
|
|
117
120
|
.filter(([key]) => !key.startsWith("_"))
|
|
118
|
-
.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
this.countryMetadata = countries;
|
|
121
|
+
.forEach(([key, value]) => {
|
|
122
|
+
countriesMap.set(key, value); // <--- CHANGED (using .set())
|
|
123
|
+
});
|
|
124
|
+
this.countryMetadata = countriesMap; // <--- CHANGED
|
|
123
125
|
this.initialized = true;
|
|
124
126
|
}
|
|
125
127
|
catch (error) {
|
|
@@ -129,16 +131,16 @@ export class GlobalPhoneNumberService {
|
|
|
129
131
|
/**
|
|
130
132
|
* Gets the metadata for a specific country
|
|
131
133
|
*
|
|
132
|
-
* @param {
|
|
134
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
133
135
|
* @returns {CountryMetadata | undefined} The country metadata or undefined if not found
|
|
134
136
|
*/
|
|
135
137
|
getCountryMetadata(countryCode) {
|
|
136
|
-
return this.countryMetadata
|
|
138
|
+
return this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
137
139
|
}
|
|
138
140
|
/**
|
|
139
141
|
* Gets all country metadata
|
|
140
142
|
*
|
|
141
|
-
* @returns {CountryMetadataMap} All country metadata
|
|
143
|
+
* @returns {CountryMetadataMap} All country metadata (as a Map)
|
|
142
144
|
*/
|
|
143
145
|
getAllCountryMetadata() {
|
|
144
146
|
return this.countryMetadata;
|
|
@@ -151,6 +153,7 @@ export class GlobalPhoneNumberService {
|
|
|
151
153
|
*/
|
|
152
154
|
getCountriesWithDialCode(dialCode) {
|
|
153
155
|
const dialCodeStr = dialCode.toString();
|
|
156
|
+
// sharedCountryCodes remains an object, access is unchanged
|
|
154
157
|
return this.sharedCountryCodes[dialCodeStr] || [];
|
|
155
158
|
}
|
|
156
159
|
/**
|
|
@@ -161,6 +164,7 @@ export class GlobalPhoneNumberService {
|
|
|
161
164
|
*/
|
|
162
165
|
isSharedDialCode(dialCode) {
|
|
163
166
|
const dialCodeStr = dialCode.toString();
|
|
167
|
+
// sharedCountryCodes remains an object, access is unchanged
|
|
164
168
|
const countries = this.sharedCountryCodes[dialCodeStr];
|
|
165
169
|
return countries !== undefined && countries.length > 1;
|
|
166
170
|
}
|
|
@@ -171,9 +175,10 @@ export class GlobalPhoneNumberService {
|
|
|
171
175
|
* @returns The country code or undefined if not found
|
|
172
176
|
*/
|
|
173
177
|
getCountryForDialCode(dialCode) {
|
|
174
|
-
|
|
178
|
+
// Iterate over Map entries
|
|
179
|
+
for (const [countryCode, metadata] of this.countryMetadata.entries()) { // <--- CHANGED (using .entries())
|
|
175
180
|
if (metadata.code.toString() === dialCode) {
|
|
176
|
-
return countryCode;
|
|
181
|
+
return countryCode; // No need for type assertion here
|
|
177
182
|
}
|
|
178
183
|
}
|
|
179
184
|
return undefined;
|
|
@@ -193,23 +198,24 @@ export class GlobalPhoneNumberService {
|
|
|
193
198
|
for (let i = 3; i >= 1; i--) {
|
|
194
199
|
if (numberWithoutPlus.length <= i)
|
|
195
200
|
continue;
|
|
196
|
-
const
|
|
197
|
-
// Check if any country has this dial code
|
|
201
|
+
const potentialDialCode = numberWithoutPlus.substring(0, i); // Renamed for clarity
|
|
202
|
+
// Check if any country has this dial code by iterating Map values
|
|
198
203
|
let countryFound = false;
|
|
199
|
-
for (const
|
|
200
|
-
if (metadata.code.toString() ===
|
|
204
|
+
for (const metadata of this.countryMetadata.values()) { // <--- CHANGED (using .values())
|
|
205
|
+
if (metadata.code.toString() === potentialDialCode) {
|
|
201
206
|
countryFound = true;
|
|
202
207
|
break;
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
if (countryFound) {
|
|
206
|
-
const nationalNumber = numberWithoutPlus.substring(
|
|
207
|
-
const isShared = this.isSharedDialCode(
|
|
211
|
+
const nationalNumber = numberWithoutPlus.substring(potentialDialCode.length);
|
|
212
|
+
const isShared = this.isSharedDialCode(potentialDialCode);
|
|
213
|
+
// Use the existing methods which now work with the Map internally
|
|
208
214
|
const possibleCountries = isShared
|
|
209
|
-
? this.sharedCountryCodes[
|
|
210
|
-
: [this.getCountryForDialCode(
|
|
215
|
+
? this.sharedCountryCodes[potentialDialCode] // Access shared codes directly
|
|
216
|
+
: this.getCountryForDialCode(potentialDialCode) ? [this.getCountryForDialCode(potentialDialCode)] : [];
|
|
211
217
|
return {
|
|
212
|
-
dialCode,
|
|
218
|
+
dialCode: potentialDialCode,
|
|
213
219
|
isShared,
|
|
214
220
|
nationalNumber,
|
|
215
221
|
possibleCountries,
|
|
@@ -242,7 +248,7 @@ export class GlobalPhoneNumberService {
|
|
|
242
248
|
/**
|
|
243
249
|
* Determines the most likely type of a phone number
|
|
244
250
|
*
|
|
245
|
-
* @param {
|
|
251
|
+
* @param {ISO2CountryCode} countryCode - ISO country code
|
|
246
252
|
* @param {string} nationalNumber - The national number to check
|
|
247
253
|
* @returns {PhoneNumberType} The type of the phone number
|
|
248
254
|
*/
|
|
@@ -250,8 +256,10 @@ export class GlobalPhoneNumberService {
|
|
|
250
256
|
if (!countryCode || !nationalNumber) {
|
|
251
257
|
return PhoneNumberType.UNKNOWN;
|
|
252
258
|
}
|
|
253
|
-
|
|
254
|
-
|
|
259
|
+
// Use .get() to retrieve metadata
|
|
260
|
+
const metadata = this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
261
|
+
// Check if metadata exists after .get()
|
|
262
|
+
if (!metadata || !metadata.patterns) { // <--- ADDED Check for undefined
|
|
255
263
|
return PhoneNumberType.UNKNOWN;
|
|
256
264
|
}
|
|
257
265
|
// Verify that required patterns exist
|
|
@@ -278,7 +286,7 @@ export class GlobalPhoneNumberService {
|
|
|
278
286
|
/**
|
|
279
287
|
* Validates a phone number against country-specific patterns
|
|
280
288
|
*
|
|
281
|
-
* @param {
|
|
289
|
+
* @param {ISO2CountryCode} countryCode - ISO country code
|
|
282
290
|
* @param {string} nationalNumber - The national number to validate
|
|
283
291
|
* @returns {boolean} True if the phone number is valid, false otherwise
|
|
284
292
|
*/
|
|
@@ -286,8 +294,10 @@ export class GlobalPhoneNumberService {
|
|
|
286
294
|
if (!countryCode || !nationalNumber) {
|
|
287
295
|
return false;
|
|
288
296
|
}
|
|
289
|
-
|
|
290
|
-
|
|
297
|
+
// Use .get() to retrieve metadata
|
|
298
|
+
const metadata = this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
299
|
+
// Check if metadata exists after .get()
|
|
300
|
+
if (!metadata || !metadata.patterns) { // <--- ADDED Check for undefined
|
|
291
301
|
return false;
|
|
292
302
|
}
|
|
293
303
|
// Verify that required patterns exist
|
|
@@ -313,6 +323,7 @@ export class GlobalPhoneNumberService {
|
|
|
313
323
|
}
|
|
314
324
|
/**
|
|
315
325
|
* Formats a phone number according to the country's formatting rules
|
|
326
|
+
* (No changes needed in this method's logic)
|
|
316
327
|
*
|
|
317
328
|
* @param {string} phoneNumber - The phone number to format
|
|
318
329
|
* @param {PhoneNumberFormat} format - The desired format
|
|
@@ -326,6 +337,7 @@ export class GlobalPhoneNumberService {
|
|
|
326
337
|
}
|
|
327
338
|
/**
|
|
328
339
|
* Creates a PhoneNumber from an international format string
|
|
340
|
+
* (No changes needed in this method's logic)
|
|
329
341
|
*
|
|
330
342
|
* @param {string} phoneNumber - The phone number in international format
|
|
331
343
|
* @returns {PhoneNumber | undefined} The parsed phone number or undefined if invalid
|
|
@@ -335,6 +347,7 @@ export class GlobalPhoneNumberService {
|
|
|
335
347
|
}
|
|
336
348
|
/**
|
|
337
349
|
* Creates a PhoneNumber from a phone number with explicit country
|
|
350
|
+
* (No changes needed in this method's logic)
|
|
338
351
|
*
|
|
339
352
|
* @param {string} phoneNumber - The phone number in any format
|
|
340
353
|
* @param {Country | string} country - The country or country code
|
|
@@ -350,6 +363,7 @@ export class GlobalPhoneNumberService {
|
|
|
350
363
|
}
|
|
351
364
|
/**
|
|
352
365
|
* Extracts the information needed for dialing from one country to another
|
|
366
|
+
* (No changes needed in this method's logic)
|
|
353
367
|
*
|
|
354
368
|
* @param {string} fromCountry - ISO code of the country dialing from
|
|
355
369
|
* @param {PhoneNumber} phoneNumber - The phone number to dial
|
|
@@ -365,6 +379,7 @@ export class GlobalPhoneNumberService {
|
|
|
365
379
|
}
|
|
366
380
|
/**
|
|
367
381
|
* Cleans a phone number by removing all non-digit characters except the leading plus
|
|
382
|
+
* (No changes needed in this method's logic)
|
|
368
383
|
*
|
|
369
384
|
* @param {string} phoneNumber - The phone number to clean
|
|
370
385
|
* @returns {string} The cleaned phone number
|
|
@@ -381,6 +396,7 @@ export class GlobalPhoneNumberService {
|
|
|
381
396
|
}
|
|
382
397
|
/**
|
|
383
398
|
* Extracts the country and national number from an international phone number
|
|
399
|
+
* (No changes needed in this method's logic - relies on extractDialCode which was updated)
|
|
384
400
|
*
|
|
385
401
|
* @param {string} phoneNumber - The phone number in international format
|
|
386
402
|
* @returns {[Country | undefined, string]} The country and national number
|
|
@@ -406,25 +422,29 @@ export class GlobalPhoneNumberService {
|
|
|
406
422
|
/**
|
|
407
423
|
* Gets a list of commonly used examples of valid phone numbers for a country
|
|
408
424
|
*
|
|
409
|
-
* @param {
|
|
425
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
410
426
|
* @returns {string[]} Array of example phone numbers
|
|
411
427
|
*/
|
|
412
428
|
getExampleNumbers(countryCode) {
|
|
413
|
-
|
|
429
|
+
// Use .get() to retrieve metadata
|
|
430
|
+
const metadata = this.countryMetadata.get(countryCode); // <--- CHANGED (using .get())
|
|
414
431
|
if (!metadata)
|
|
415
|
-
return [];
|
|
432
|
+
return []; // <--- ADDED Check for undefined
|
|
416
433
|
const dialCode = metadata.code;
|
|
417
434
|
const examples = [];
|
|
418
|
-
//
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
435
|
+
// Ensure patterns exist before trying to generate examples
|
|
436
|
+
if (metadata.patterns.landline) {
|
|
437
|
+
examples.push(`+${dialCode}${this.generateExampleFromPattern(metadata.patterns.landline)}`);
|
|
438
|
+
}
|
|
439
|
+
if (metadata.patterns.mobile) {
|
|
440
|
+
examples.push(`+${dialCode}${this.generateExampleFromPattern(metadata.patterns.mobile)}`);
|
|
441
|
+
}
|
|
423
442
|
return examples;
|
|
424
443
|
}
|
|
425
444
|
/**
|
|
426
445
|
* Generates an example phone number that would match a given pattern
|
|
427
446
|
* This is a simple implementation that handles basic patterns
|
|
447
|
+
* (No changes needed in this method's logic)
|
|
428
448
|
*
|
|
429
449
|
* @param pattern - The regex pattern
|
|
430
450
|
* @returns A string that would match the pattern
|
|
@@ -443,9 +463,10 @@ export class GlobalPhoneNumberService {
|
|
|
443
463
|
}
|
|
444
464
|
/**
|
|
445
465
|
* Checks if a phone number is valid for a specific country
|
|
466
|
+
* (No changes needed in this method's logic)
|
|
446
467
|
*
|
|
447
468
|
* @param {string} phoneNumber - The phone number to validate
|
|
448
|
-
* @param {
|
|
469
|
+
* @param {ISO2CountryCode} countryCode - The ISO country code
|
|
449
470
|
* @returns {boolean} True if the phone number is valid for the country, false otherwise
|
|
450
471
|
*/
|
|
451
472
|
isValidForCountry(phoneNumber, countryCode) {
|
|
@@ -462,12 +483,12 @@ export class GlobalPhoneNumberService {
|
|
|
462
483
|
* @returns True if the dial code exists, false otherwise
|
|
463
484
|
*/
|
|
464
485
|
hasDialCode(dialCode) {
|
|
465
|
-
// Check if it's a shared dial code
|
|
486
|
+
// Check if it's a shared dial code (access unchanged)
|
|
466
487
|
if (this.sharedCountryCodes[dialCode]?.length > 0) {
|
|
467
488
|
return true;
|
|
468
489
|
}
|
|
469
|
-
// Check if any country has this dial code
|
|
470
|
-
for (const metadata of
|
|
490
|
+
// Check if any country has this dial code by iterating Map values
|
|
491
|
+
for (const metadata of this.countryMetadata.values()) { // <--- CHANGED (using .values())
|
|
471
492
|
if (metadata.code.toString() === dialCode) {
|
|
472
493
|
return true;
|
|
473
494
|
}
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ declare const _default: {
|
|
|
15
15
|
coverage: string;
|
|
16
16
|
contact_info: string;
|
|
17
17
|
notes: string;
|
|
18
|
-
countries: {
|
|
18
|
+
countries: ({
|
|
19
19
|
name: string;
|
|
20
20
|
name_official: string;
|
|
21
21
|
iso_2: string;
|
|
@@ -23,7 +23,17 @@ declare const _default: {
|
|
|
23
23
|
flag_emoji: string;
|
|
24
24
|
continent: string;
|
|
25
25
|
region: string;
|
|
26
|
-
|
|
26
|
+
currency_iso_code: string;
|
|
27
|
+
} | {
|
|
28
|
+
name: string;
|
|
29
|
+
name_official: string;
|
|
30
|
+
iso_2: string;
|
|
31
|
+
iso_3: string;
|
|
32
|
+
flag_emoji: string;
|
|
33
|
+
continent: string;
|
|
34
|
+
region: string;
|
|
35
|
+
currency_iso_code: null;
|
|
36
|
+
})[];
|
|
27
37
|
};
|
|
28
38
|
export default _default;
|
|
29
39
|
//# sourceMappingURL=countries.d.ts.map
|