libphonenumber-js 1.11.1 → 1.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/AsYouType.test.js +33 -23
  2. package/build/AsYouType.test.js.map +1 -1
  3. package/build/PhoneNumberMatcher.test.js +6 -5
  4. package/build/PhoneNumberMatcher.test.js.map +1 -1
  5. package/build/format.test.js +1 -1
  6. package/build/format.test.js.map +1 -1
  7. package/build/legacy/format.test.js +1 -1
  8. package/build/legacy/format.test.js.map +1 -1
  9. package/build/legacy/parse.test.js +28 -20
  10. package/build/legacy/parse.test.js.map +1 -1
  11. package/build/parse.test.js +28 -20
  12. package/build/parse.test.js.map +1 -1
  13. package/bundle/libphonenumber-js.min.js +1 -1
  14. package/bundle/libphonenumber-js.min.js.map +1 -1
  15. package/bundle/libphonenumber-max.js +1 -1
  16. package/bundle/libphonenumber-max.js.map +1 -1
  17. package/bundle/libphonenumber-min.js +1 -1
  18. package/bundle/libphonenumber-min.js.map +1 -1
  19. package/bundle/libphonenumber-mobile.js +1 -1
  20. package/bundle/libphonenumber-mobile.js.map +1 -1
  21. package/es6/AsYouType.test.js +33 -23
  22. package/es6/AsYouType.test.js.map +1 -1
  23. package/es6/PhoneNumberMatcher.test.js +6 -5
  24. package/es6/PhoneNumberMatcher.test.js.map +1 -1
  25. package/es6/format.test.js +1 -1
  26. package/es6/format.test.js.map +1 -1
  27. package/es6/legacy/format.test.js +1 -1
  28. package/es6/legacy/format.test.js.map +1 -1
  29. package/es6/legacy/parse.test.js +28 -20
  30. package/es6/legacy/parse.test.js.map +1 -1
  31. package/es6/parse.test.js +28 -20
  32. package/es6/parse.test.js.map +1 -1
  33. package/examples.mobile.json +1 -1
  34. package/examples.mobile.json.js +1 -1
  35. package/metadata.full.json +1 -1
  36. package/metadata.full.json.js +1 -1
  37. package/metadata.max.json +1 -1
  38. package/metadata.max.json.js +1 -1
  39. package/metadata.min.json +1 -1
  40. package/metadata.min.json.js +1 -1
  41. package/metadata.mobile.json +1 -1
  42. package/metadata.mobile.json.js +1 -1
  43. package/package.json +1 -1
  44. package/source/AsYouType.test.js +36 -20
  45. package/source/PhoneNumberMatcher.test.js +7 -4
  46. package/source/format.test.js +1 -1
  47. package/source/legacy/format.test.js +1 -1
  48. package/source/legacy/parse.test.js +27 -18
  49. package/source/parse.test.js +27 -18
  50. package/types.d.cts +9 -14
  51. package/types.d.ts +9 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.11.1",
3
+ "version": "1.11.3",
4
4
  "description": "A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -750,37 +750,53 @@ describe('AsYouType', () => {
750
750
 
751
751
  it('should work with Mexico numbers', () => {
752
752
  const asYouType = new AsYouType('MX')
753
- // Fixed line.
753
+
754
+ // Fixed line. International.
754
755
  asYouType.input('+52(449)978-000').should.equal('+52 449 978 000')
755
756
  asYouType.input('1').should.equal('+52 449 978 0001')
756
757
  asYouType.reset()
757
- asYouType.input('01449978000').should.equal('01449 978 000')
758
- asYouType.getTemplate().should.equal('xxxxx xxx xxx')
759
- asYouType.input('1').should.equal('01449 978 0001')
760
- asYouType.getTemplate().should.equal('xxxxx xxx xxxx')
761
- asYouType.reset()
758
+
759
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
760
+ // no longer valid since August 2019."
761
+ // // Fixed line. National. With national prefix "01".
762
+ // asYouType.input('01449978000').should.equal('01449 978 000')
763
+ // asYouType.getTemplate().should.equal('xxxxx xxx xxx')
764
+ // asYouType.input('1').should.equal('01449 978 0001')
765
+ // asYouType.getTemplate().should.equal('xxxxx xxx xxxx')
766
+ // asYouType.reset()
767
+
768
+ // Fixed line. National. Without national prefix.
762
769
  asYouType.input('(449)978-000').should.equal('449 978 000')
763
770
  asYouType.getTemplate().should.equal('xxx xxx xxx')
764
771
  asYouType.input('1').should.equal('449 978 0001')
765
772
  asYouType.getTemplate().should.equal('xxx xxx xxxx')
766
- // Mobile.
767
- // `1` is prepended before area code to mobile numbers in international format.
768
- asYouType.reset()
769
- asYouType.input('+521331234567').should.equal('+52 133 1234 567')
770
- asYouType.getTemplate().should.equal('xxx xxx xxxx xxx')
771
- // Google's `libphonenumber` seems to not able to format this type of number.
772
- // https://issuetracker.google.com/issues/147938979
773
- asYouType.input('8').should.equal('+52 133 1234 5678')
774
- asYouType.getTemplate().should.equal('xxx xxx xxxx xxxx')
775
773
  asYouType.reset()
774
+
775
+ // Mobile.
776
776
  asYouType.input('+52331234567').should.equal('+52 33 1234 567')
777
777
  asYouType.input('8').should.equal('+52 33 1234 5678')
778
778
  asYouType.reset()
779
- asYouType.input('044331234567').should.equal('04433 1234 567')
780
- asYouType.input('8').should.equal('04433 1234 5678')
781
- asYouType.reset()
782
- asYouType.input('045331234567').should.equal('04533 1234 567')
783
- asYouType.input('8').should.equal('04533 1234 5678')
779
+
780
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
781
+ // no longer valid since August 2019."
782
+ // // Mobile.
783
+ // // With `1` prepended before area code to mobile numbers in international format.
784
+ // asYouType.input('+521331234567').should.equal('+52 133 1234 567')
785
+ // asYouType.getTemplate().should.equal('xxx xxx xxxx xxx')
786
+ // // Google's `libphonenumber` seems to not able to format this type of number.
787
+ // // https://issuetracker.google.com/issues/147938979
788
+ // asYouType.input('8').should.equal('+52 133 1234 5678')
789
+ // asYouType.getTemplate().should.equal('xxx xxx xxxx xxxx')
790
+ // asYouType.reset()
791
+ //
792
+ // // Mobile. National. With "044" prefix.
793
+ // asYouType.input('044331234567').should.equal('04433 1234 567')
794
+ // asYouType.input('8').should.equal('04433 1234 5678')
795
+ // asYouType.reset()
796
+ //
797
+ // // Mobile. National. With "045" prefix.
798
+ // asYouType.input('045331234567').should.equal('04533 1234 567')
799
+ // asYouType.input('8').should.equal('04533 1234 5678')
784
800
  })
785
801
 
786
802
  it('should just prepend national prefix if national_prefix_formatting_rule does not produce a suitable number', () => {
@@ -47,10 +47,13 @@ describe('PhoneNumberMatcher', () => {
47
47
  test('+52 (449)978-0001', 'MX', '4499780001')
48
48
  test('01 (449)978-0001', 'MX', '4499780001')
49
49
  test('(449)978-0001', 'MX', '4499780001')
50
- // Test parsing mobile numbers of Mexico.
51
- test('+52 1 33 1234-5678', 'MX', '3312345678')
52
- test('044 (33) 1234-5678', 'MX', '3312345678')
53
- test('045 33 1234-5678', 'MX', '3312345678')
50
+
51
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
52
+ // no longer valid since August 2019."
53
+ // // Test parsing mobile numbers of Mexico.
54
+ // test('+52 1 33 1234-5678', 'MX', '3312345678')
55
+ // test('044 (33) 1234-5678', 'MX', '3312345678')
56
+ // test('045 33 1234-5678', 'MX', '3312345678')
54
57
  })
55
58
 
56
59
  it('should find phone numbers from Argentina', () => {
@@ -260,6 +260,6 @@ describe('format', () => {
260
260
  it('should use the default IDD prefix when formatting a phone number', () => {
261
261
  // Testing preferred international prefixes with ~ are supported.
262
262
  // ("~" designates waiting on a line until proceeding with the input).
263
- formatNumber('+390236618300', 'IDD', { fromCountry: 'UZ' }).should.equal('8~10 39 02 3661 8300')
263
+ formatNumber('+390236618300', 'IDD', { fromCountry: 'BY' }).should.equal('8~10 39 02 3661 8300')
264
264
  })
265
265
  })
@@ -235,6 +235,6 @@ describe('format', () => {
235
235
  it('should use the default IDD prefix when formatting a phone number', () => {
236
236
  // Testing preferred international prefixes with ~ are supported.
237
237
  // ("~" designates waiting on a line until proceeding with the input).
238
- formatNumber('+390236618300', 'IDD', { fromCountry: 'UZ' }).should.equal('8~10 39 02 3661 8300')
238
+ formatNumber('+390236618300', 'IDD', { fromCountry: 'BY' }).should.equal('8~10 39 02 3661 8300')
239
239
  })
240
240
  })
@@ -353,32 +353,41 @@ describe('parse', () => {
353
353
  country: 'MX',
354
354
  phone: '4499780001'
355
355
  })
356
- parseNumber('01 (449)978-0001', 'MX').should.deep.equal({
357
- country: 'MX',
358
- phone: '4499780001'
359
- })
356
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
357
+ // no longer valid since August 2019."
358
+ //
359
+ // parseNumber('01 (449)978-0001', 'MX').should.deep.equal({
360
+ // country: 'MX',
361
+ // phone: '4499780001'
362
+ // })
360
363
  parseNumber('(449)978-0001', 'MX').should.deep.equal({
361
364
  country: 'MX',
362
365
  phone: '4499780001'
363
366
  })
364
- // Mobile.
365
- // `1` is prepended before area code to mobile numbers in international format.
366
- parseNumber('+52 1 33 1234-5678', 'MX').should.deep.equal({
367
- country: 'MX',
368
- phone: '3312345678'
369
- })
367
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
368
+ // no longer valid since August 2019."
369
+ //
370
+ // // Mobile.
371
+ // // `1` is prepended before area code to mobile numbers in international format.
372
+ // parseNumber('+52 1 33 1234-5678', 'MX').should.deep.equal({
373
+ // country: 'MX',
374
+ // phone: '3312345678'
375
+ // })
370
376
  parseNumber('+52 33 1234-5678', 'MX').should.deep.equal({
371
377
  country: 'MX',
372
378
  phone: '3312345678'
373
379
  })
374
- parseNumber('044 (33) 1234-5678', 'MX').should.deep.equal({
375
- country: 'MX',
376
- phone: '3312345678'
377
- })
378
- parseNumber('045 33 1234-5678', 'MX').should.deep.equal({
379
- country: 'MX',
380
- phone: '3312345678'
381
- })
380
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
381
+ // no longer valid since August 2019."
382
+ //
383
+ // parseNumber('044 (33) 1234-5678', 'MX').should.deep.equal({
384
+ // country: 'MX',
385
+ // phone: '3312345678'
386
+ // })
387
+ // parseNumber('045 33 1234-5678', 'MX').should.deep.equal({
388
+ // country: 'MX',
389
+ // phone: '3312345678'
390
+ // })
382
391
  })
383
392
 
384
393
  it('should parse non-geographic numbering plan phone numbers', () => {
@@ -368,32 +368,41 @@ describe('parse', () => {
368
368
  country: 'MX',
369
369
  phone: '4499780001'
370
370
  })
371
- parseNumber('01 (449)978-0001', 'MX').should.deep.equal({
372
- country: 'MX',
373
- phone: '4499780001'
374
- })
371
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
372
+ // no longer valid since August 2019."
373
+ //
374
+ // parseNumber('01 (449)978-0001', 'MX').should.deep.equal({
375
+ // country: 'MX',
376
+ // phone: '4499780001'
377
+ // })
375
378
  parseNumber('(449)978-0001', 'MX').should.deep.equal({
376
379
  country: 'MX',
377
380
  phone: '4499780001'
378
381
  })
379
- // Mobile.
380
- // `1` is prepended before area code to mobile numbers in international format.
381
- parseNumber('+52 1 33 1234-5678', 'MX').should.deep.equal({
382
- country: 'MX',
383
- phone: '3312345678'
384
- })
382
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
383
+ // no longer valid since August 2019."
384
+ //
385
+ // // Mobile.
386
+ // // `1` is prepended before area code to mobile numbers in international format.
387
+ // parseNumber('+52 1 33 1234-5678', 'MX').should.deep.equal({
388
+ // country: 'MX',
389
+ // phone: '3312345678'
390
+ // })
385
391
  parseNumber('+52 33 1234-5678', 'MX').should.deep.equal({
386
392
  country: 'MX',
387
393
  phone: '3312345678'
388
394
  })
389
- parseNumber('044 (33) 1234-5678', 'MX').should.deep.equal({
390
- country: 'MX',
391
- phone: '3312345678'
392
- })
393
- parseNumber('045 33 1234-5678', 'MX').should.deep.equal({
394
- country: 'MX',
395
- phone: '3312345678'
396
- })
395
+ // "Dialling tokens 01, 02, 044, 045 and 1 are removed as they are
396
+ // no longer valid since August 2019."
397
+ //
398
+ // parseNumber('044 (33) 1234-5678', 'MX').should.deep.equal({
399
+ // country: 'MX',
400
+ // phone: '3312345678'
401
+ // })
402
+ // parseNumber('045 33 1234-5678', 'MX').should.deep.equal({
403
+ // country: 'MX',
404
+ // phone: '3312345678'
405
+ // })
397
406
  })
398
407
 
399
408
  it('should parse non-geographic numbering plan phone numbers', () => {
package/types.d.cts CHANGED
@@ -70,21 +70,16 @@ export type NumberType = undefined | 'PREMIUM_RATE' | 'TOLL_FREE' | 'SHARED_COST
70
70
  // Shows an error:
71
71
  // Type 'E164Number' is not assignable to type 'CarrierCode'.
72
72
  //
73
- // The `__tag` property is declared optional in order to allow passing a `string`
74
- // in place of a `Tagged` argument to functions that receive such arguments.
75
- // There currently are no such functions in this package, but in case there were any,
76
- // in their arguments they'd accept both a `string` and the `Tagged` type of the argument.
73
+ // Originally, the `__tag` property was declared optional in order to allow passing
74
+ // a generic `string` in place of a `Tagged` type argument to functions that receive such arguments:
75
+ // that would allow ingesting generic `string` values from an outside source such as a database.
76
+ // Without that, those externally-obtained `string` values would have to be forcefully converted
77
+ // to the `Tagged` type via TypeScript `as` operator which is an anti-pattern.
77
78
  //
78
- // The `__tag` property could also be declared non-optional but what issue would it solve?
79
- // It would disallow assigning a `string` to an `E164Number` variable, but what would be the props of such approach?
80
- // For example, the following code wouldn't compile:
81
- //
82
- // const number: E164Number = "some random text"
83
- //
84
- // But in that case, how would one initialize an `E164Number` variable with a value received from outside?
85
- // For example, a program reads an `E.164` number from a database in the form of a `string`.
86
- // How would it cast it to an `E164Number`? Using `as` keyword?
87
- // In that case it wouldn't really make any difference from allowing it to assign a `string` to a `E164Number` variable directly.
79
+ // Later, it has been decided to make the `__tag` property non-optional and instead
80
+ // declare the arguments of those functions as `string | Tagged` rather than just `Tagged`:
81
+ // that would still allow ingesting generic `string` values from an outside source
82
+ // and would also make the `Tagged` type more "type safe".
88
83
  //
89
84
  type Tagged<A, T> = A & { __tag: T };
90
85
 
package/types.d.ts CHANGED
@@ -70,21 +70,16 @@ export type NumberType = undefined | 'PREMIUM_RATE' | 'TOLL_FREE' | 'SHARED_COST
70
70
  // Shows an error:
71
71
  // Type 'E164Number' is not assignable to type 'CarrierCode'.
72
72
  //
73
- // The `__tag` property is declared optional in order to allow passing a `string`
74
- // in place of a `Tagged` argument to functions that receive such arguments.
75
- // There currently are no such functions in this package, but in case there were any,
76
- // in their arguments they'd accept both a `string` and the `Tagged` type of the argument.
73
+ // Originally, the `__tag` property was declared optional in order to allow passing
74
+ // a generic `string` in place of a `Tagged` type argument to functions that receive such arguments:
75
+ // that would allow ingesting generic `string` values from an outside source such as a database.
76
+ // Without that, those externally-obtained `string` values would have to be forcefully converted
77
+ // to the `Tagged` type via TypeScript `as` operator which is an anti-pattern.
77
78
  //
78
- // The `__tag` property could also be declared non-optional but what issue would it solve?
79
- // It would disallow assigning a `string` to an `E164Number` variable, but what would be the props of such approach?
80
- // For example, the following code wouldn't compile:
81
- //
82
- // const number: E164Number = "some random text"
83
- //
84
- // But in that case, how would one initialize an `E164Number` variable with a value received from outside?
85
- // For example, a program reads an `E.164` number from a database in the form of a `string`.
86
- // How would it cast it to an `E164Number`? Using `as` keyword?
87
- // In that case it wouldn't really make any difference from allowing it to assign a `string` to a `E164Number` variable directly.
79
+ // Later, it has been decided to make the `__tag` property non-optional and instead
80
+ // declare the arguments of those functions as `string | Tagged` rather than just `Tagged`:
81
+ // that would still allow ingesting generic `string` values from an outside source
82
+ // and would also make the `Tagged` type more "type safe".
88
83
  //
89
84
  type Tagged<A, T> = A & { __tag: T };
90
85