fullstack-phone 1.148.0 → 1.149.0

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/CHANGELOG.md CHANGED
@@ -1,13 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.149.0
4
+
5
+ * Added Typescript declaration files
6
+
3
7
  ## 1.148.0
4
8
 
5
9
  * Metadata:
6
10
  * Updated to libphonenumber v8.13.32
7
11
 
8
12
  ## 1.147.1
13
+
9
14
  * Bugfix:
10
- * Restore `client/index.js` to ES5 (was generated with ESNEXT in v1.142.0)
15
+ * Restored `client/index.js` to ES5 (was generated with ESNEXT in v1.142.0)
11
16
 
12
17
  ## 1.147.0
13
18
 
@@ -0,0 +1,143 @@
1
+ import type {
2
+ RegionCode,
3
+ Meta,
4
+ CountryCallingCodeNumeric,
5
+ CountryCodeToRegionCodeMap,
6
+ } from '../server';
7
+
8
+ interface PhoneObj {
9
+ countryCode: string;
10
+ nationalNumber: string;
11
+ extension?: string;
12
+ }
13
+
14
+ type PhoneNumberType =
15
+ | 'FIXED_LINE'
16
+ | 'MOBILE'
17
+ | 'FIXED_LINE_OR_MOBILE'
18
+ | 'TOLL_FREE'
19
+ | 'PREMIUM_RATE'
20
+ | 'SHARED_COST'
21
+ | 'VOIP'
22
+ | 'PERSONAL_NUMBER'
23
+ | 'PAGER'
24
+ | 'UAN'
25
+ | 'VOICEMAIL'
26
+ | 'UNKNOWN';
27
+
28
+ interface FormatOptions {
29
+ style: 'e164' | 'international' | 'national' | 'rfc3966';
30
+ }
31
+
32
+ type FullPhoneValidationErrorMessage = 'PHONE_INVALID_FOR_REGION'
33
+ | 'PHONE_INVALID_COUNTRY_CODE'
34
+ | 'PHONE_NUMBER_TOO_LONG'
35
+ | 'PHONE_NUMBER_TOO_SHORT'
36
+ | 'PHONE_NUMBER_INVALID_LENGTH';
37
+
38
+ interface FullValidationError extends Error {
39
+ message: FullPhoneValidationErrorMessage;
40
+ }
41
+
42
+ interface LengthValidationError extends Error {
43
+ message: FullPhoneValidationErrorMessage | 'PHONE_NUMBER_POSSIBLE_LOCAL_ONLY';
44
+ }
45
+
46
+ interface ParseError extends Error {
47
+ message:
48
+ | 'PHONE_INVALID_COUNTRY_CODE'
49
+ | 'PHONE_NUMBER_TOO_SHORT'
50
+ | 'PHONE_NUMBER_TOO_LONG'
51
+ | 'PHONE_NOT_A_NUMBER'
52
+ | 'PHONE_TOO_SHORT_AFTER_IDD';
53
+ }
54
+
55
+ interface PhoneHandler {
56
+ /**
57
+ * Return the list of region codes supported by the loaded metadata
58
+ */
59
+ getSupportedRegions: () => Array<RegionCode>;
60
+
61
+ /**
62
+ * Return the country calling code for a particular region code
63
+ */
64
+ getCountryCodeForRegion: (regionCode: RegionCode) => CountryCallingCodeNumeric;
65
+
66
+ /**
67
+ * Return a map of country calling codes to arrays of regions
68
+ */
69
+ countryCodeToRegionCodeMap: () => CountryCodeToRegionCodeMap;
70
+
71
+ /**
72
+ * Return the type of a (valid) phone number
73
+ */
74
+ inferPhoneNumberType: (phoneObj: PhoneObj) => PhoneNumberType;
75
+
76
+ /**
77
+ * Return the region of a (valid) phone number
78
+ * or null if the region cannot be determined
79
+ */
80
+ inferPhoneNumberRegion: (phoneObj: PhoneObj) => RegionCode | null;
81
+
82
+ /**
83
+ * Format a phone number according to the given style
84
+ */
85
+ formatPhoneNumber: (phoneObj: PhoneObj, options: FormatOptions) => string;
86
+
87
+ /**
88
+ * Indicate whether the given phone number is valid for the given region
89
+ * If regionCode is omitted, the phone number is checked against all possible regions loaded in the metadata
90
+ */
91
+ validatePhoneNumber: (phoneObj: PhoneObj, regionCode?: RegionCode) => true | FullValidationError;
92
+
93
+ /**
94
+ * Indicate whether the given phone number is "possible" for the region (i.e., whether it adheres to length constraints)
95
+ * (More lenient than validatePhoneNumber)
96
+ * If regionCode is omitted, it is checked against all regions loaded in the metadata
97
+ */
98
+ validateLength: (phoneObj: PhoneObj, regionCode?: RegionCode) => true | LengthValidationError;
99
+
100
+ /**
101
+ * Parse a phone number string for the given region and return a phoneObj
102
+ */
103
+ parsePhoneNumber: (phoneNumberToParse: string, regionCode?: RegionCode) => PhoneObj | ParseError;
104
+
105
+ /**
106
+ * Return an example phone number for a given type and region
107
+ * or null if an example does not exist
108
+ */
109
+ getExampleNumberForType: (type: PhoneNumberType, regionCode: RegionCode) => PhoneObj | null;
110
+
111
+ /**
112
+ * Return an as-you-type formatter instantiated for the given region
113
+ */
114
+ getAsYouTypeFormatter: (regionCode: RegionCode) => AsYouTypeFormatter;
115
+ }
116
+
117
+ interface AsYouTypeFormatter {
118
+ /**
119
+ * Input a single character
120
+ * Returns the formatted output so far
121
+ */
122
+ inputDigit: (x: number | string) => string;
123
+
124
+ /**
125
+ * Clear the formatter
126
+ */
127
+ clear: () => void;
128
+
129
+ /**
130
+ * Input a single char and remember the position
131
+ */
132
+ inputDigitAndRememberPosition: (x: number | string) => string;
133
+
134
+ /**
135
+ * Return the remembered position as a number
136
+ */
137
+ getRememberedPosition: () => number;
138
+ }
139
+
140
+ /**
141
+ * Return a phone handler initialized for the given metadata bundle
142
+ */
143
+ export function createPhoneHandler(meta: Meta): PhoneHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fullstack-phone",
3
- "version": "1.148.0",
3
+ "version": "1.149.0",
4
4
  "libphonenumber": "v8.13.32",
5
5
  "description": "A dual-module phone number system with dynamic regional metadata",
6
6
  "keywords": [
@@ -0,0 +1,483 @@
1
+ export type RegionCode =
2
+ | 'AC'
3
+ | 'AD'
4
+ | 'AE'
5
+ | 'AF'
6
+ | 'AG'
7
+ | 'US'
8
+ | 'AI'
9
+ | 'AL'
10
+ | 'AM'
11
+ | 'AO'
12
+ | 'AR'
13
+ | 'AS'
14
+ | 'AT'
15
+ | 'AU'
16
+ | 'AW'
17
+ | 'AX'
18
+ | 'FI'
19
+ | 'AZ'
20
+ | 'BA'
21
+ | 'BB'
22
+ | 'BD'
23
+ | 'BE'
24
+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KG'
117
+ | 'KH'
118
+ | 'KI'
119
+ | 'KM'
120
+ | 'KN'
121
+ | 'KP'
122
+ | 'KR'
123
+ | 'KW'
124
+ | 'KY'
125
+ | 'KZ'
126
+ | 'RU'
127
+ | 'LA'
128
+ | 'LB'
129
+ | 'LC'
130
+ | 'LI'
131
+ | 'LK'
132
+ | 'LR'
133
+ | 'LS'
134
+ | 'LT'
135
+ | 'LU'
136
+ | 'LV'
137
+ | 'LY'
138
+ | 'MC'
139
+ | 'MD'
140
+ | 'ME'
141
+ | 'MF'
142
+ | 'MG'
143
+ | 'MH'
144
+ | 'MK'
145
+ | 'ML'
146
+ | 'MM'
147
+ | 'MN'
148
+ | 'MO'
149
+ | 'MP'
150
+ | 'MQ'
151
+ | 'MR'
152
+ | 'MS'
153
+ | 'MT'
154
+ | 'MU'
155
+ | 'MV'
156
+ | 'MW'
157
+ | 'MX'
158
+ | 'MY'
159
+ | 'MZ'
160
+ | 'NA'
161
+ | 'NC'
162
+ | 'NE'
163
+ | 'NF'
164
+ | 'NG'
165
+ | 'NI'
166
+ | 'NL'
167
+ | 'NO'
168
+ | 'NP'
169
+ | 'NR'
170
+ | 'NU'
171
+ | 'NZ'
172
+ | 'OM'
173
+ | 'PA'
174
+ | 'PE'
175
+ | 'PF'
176
+ | 'PG'
177
+ | 'PH'
178
+ | 'PK'
179
+ | 'PL'
180
+ | 'PM'
181
+ | 'PR'
182
+ | 'PS'
183
+ | 'PT'
184
+ | 'PW'
185
+ | 'PY'
186
+ | 'QA'
187
+ | 'RE'
188
+ | 'RO'
189
+ | 'RS'
190
+ | 'RW'
191
+ | 'SA'
192
+ | 'SB'
193
+ | 'SC'
194
+ | 'SD'
195
+ | 'SE'
196
+ | 'SG'
197
+ | 'SH'
198
+ | 'SI'
199
+ | 'SJ'
200
+ | 'SK'
201
+ | 'SL'
202
+ | 'SM'
203
+ | 'SN'
204
+ | 'SO'
205
+ | 'SR'
206
+ | 'SS'
207
+ | 'ST'
208
+ | 'SV'
209
+ | 'SX'
210
+ | 'SY'
211
+ | 'SZ'
212
+ | 'TA'
213
+ | 'TC'
214
+ | 'TD'
215
+ | 'TG'
216
+ | 'TH'
217
+ | 'TJ'
218
+ | 'TK'
219
+ | 'TL'
220
+ | 'TM'
221
+ | 'TN'
222
+ | 'TO'
223
+ | 'TR'
224
+ | 'TT'
225
+ | 'TV'
226
+ | 'TW'
227
+ | 'TZ'
228
+ | 'UA'
229
+ | 'UG'
230
+ | 'UY'
231
+ | 'UZ'
232
+ | 'VA'
233
+ | 'VC'
234
+ | 'VE'
235
+ | 'VG'
236
+ | 'VI'
237
+ | 'VN'
238
+ | 'VU'
239
+ | 'WF'
240
+ | 'WS'
241
+ | 'XK'
242
+ | 'YE'
243
+ | 'YT'
244
+ | 'ZA'
245
+ | 'ZM'
246
+ | 'ZW'
247
+ | 'PN'
248
+ | 'AN'
249
+ | '001';
250
+
251
+ export type CountryCallingCodeNumeric =
252
+ | 1
253
+ | 7
254
+ | 20
255
+ | 27
256
+ | 30
257
+ | 31
258
+ | 32
259
+ | 33
260
+ | 34
261
+ | 36
262
+ | 39
263
+ | 40
264
+ | 41
265
+ | 43
266
+ | 44
267
+ | 45
268
+ | 46
269
+ | 47
270
+ | 48
271
+ | 49
272
+ | 51
273
+ | 52
274
+ | 53
275
+ | 54
276
+ | 55
277
+ | 56
278
+ | 57
279
+ | 58
280
+ | 60
281
+ | 61
282
+ | 62
283
+ | 63
284
+ | 64
285
+ | 65
286
+ | 66
287
+ | 81
288
+ | 82
289
+ | 84
290
+ | 86
291
+ | 90
292
+ | 91
293
+ | 92
294
+ | 93
295
+ | 94
296
+ | 95
297
+ | 98
298
+ | 211
299
+ | 212
300
+ | 213
301
+ | 216
302
+ | 218
303
+ | 220
304
+ | 221
305
+ | 222
306
+ | 223
307
+ | 224
308
+ | 225
309
+ | 226
310
+ | 227
311
+ | 228
312
+ | 229
313
+ | 230
314
+ | 231
315
+ | 232
316
+ | 233
317
+ | 234
318
+ | 235
319
+ | 236
320
+ | 237
321
+ | 238
322
+ | 239
323
+ | 240
324
+ | 241
325
+ | 242
326
+ | 243
327
+ | 244
328
+ | 245
329
+ | 246
330
+ | 247
331
+ | 248
332
+ | 249
333
+ | 250
334
+ | 251
335
+ | 252
336
+ | 253
337
+ | 254
338
+ | 255
339
+ | 256
340
+ | 257
341
+ | 258
342
+ | 260
343
+ | 261
344
+ | 262
345
+ | 263
346
+ | 264
347
+ | 265
348
+ | 266
349
+ | 267
350
+ | 268
351
+ | 269
352
+ | 290
353
+ | 291
354
+ | 297
355
+ | 298
356
+ | 299
357
+ | 350
358
+ | 351
359
+ | 352
360
+ | 353
361
+ | 354
362
+ | 355
363
+ | 356
364
+ | 357
365
+ | 358
366
+ | 359
367
+ | 370
368
+ | 371
369
+ | 372
370
+ | 373
371
+ | 374
372
+ | 375
373
+ | 376
374
+ | 377
375
+ | 378
376
+ | 380
377
+ | 381
378
+ | 382
379
+ | 383
380
+ | 385
381
+ | 386
382
+ | 387
383
+ | 389
384
+ | 420
385
+ | 421
386
+ | 423
387
+ | 500
388
+ | 501
389
+ | 502
390
+ | 503
391
+ | 504
392
+ | 505
393
+ | 506
394
+ | 507
395
+ | 508
396
+ | 509
397
+ | 590
398
+ | 591
399
+ | 592
400
+ | 593
401
+ | 594
402
+ | 595
403
+ | 596
404
+ | 597
405
+ | 598
406
+ | 599
407
+ | 670
408
+ | 672
409
+ | 673
410
+ | 674
411
+ | 675
412
+ | 676
413
+ | 677
414
+ | 678
415
+ | 679
416
+ | 680
417
+ | 681
418
+ | 682
419
+ | 683
420
+ | 685
421
+ | 686
422
+ | 687
423
+ | 688
424
+ | 689
425
+ | 690
426
+ | 691
427
+ | 692
428
+ | 800
429
+ | 808
430
+ | 850
431
+ | 852
432
+ | 853
433
+ | 855
434
+ | 856
435
+ | 870
436
+ | 878
437
+ | 880
438
+ | 881
439
+ | 882
440
+ | 883
441
+ | 886
442
+ | 888
443
+ | 960
444
+ | 961
445
+ | 962
446
+ | 963
447
+ | 964
448
+ | 965
449
+ | 966
450
+ | 967
451
+ | 968
452
+ | 970
453
+ | 971
454
+ | 972
455
+ | 973
456
+ | 974
457
+ | 975
458
+ | 976
459
+ | 977
460
+ | 979
461
+ | 992
462
+ | 993
463
+ | 994
464
+ | 995
465
+ | 996
466
+ | 998;
467
+
468
+ export type CountryCallingCodeString = `${CountryCallingCodeNumeric}`;
469
+
470
+ export type CountryCodeToRegionCodeMap = Partial<Record<CountryCallingCodeString, Array<RegionCode>>>;
471
+
472
+ export interface Meta {
473
+ regionCodes: Array<RegionCode>;
474
+ countryCodeToRegionCodeMap: CountryCodeToRegionCodeMap;
475
+ countryToMetadata: Partial<Record<RegionCode, Array<any>>>;
476
+ }
477
+
478
+ /**
479
+ * Given array of region codes whose metadata is desired,
480
+ * Return libphonenumber metadata for those regions,
481
+ * including the necessary metadata for the main countries for each country calling code
482
+ */
483
+ export function loadMeta(regionCodeArray?: Array<RegionCode>): Meta;