libphonenumber-js 1.11.4 → 1.11.17

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 (37) hide show
  1. package/README.md +1 -1
  2. package/build/AsYouType.test.js +8 -3
  3. package/build/AsYouType.test.js.map +1 -1
  4. package/build/helpers/getCountryByNationalNumber.js +17 -17
  5. package/build/helpers/getCountryByNationalNumber.js.map +1 -1
  6. package/build/parse.test.js +7 -3
  7. package/build/parse.test.js.map +1 -1
  8. package/bundle/libphonenumber-js.min.js +1 -1
  9. package/bundle/libphonenumber-js.min.js.map +1 -1
  10. package/bundle/libphonenumber-max.js +1 -1
  11. package/bundle/libphonenumber-max.js.map +1 -1
  12. package/bundle/libphonenumber-min.js +1 -1
  13. package/bundle/libphonenumber-min.js.map +1 -1
  14. package/bundle/libphonenumber-mobile.js +1 -1
  15. package/bundle/libphonenumber-mobile.js.map +1 -1
  16. package/es6/AsYouType.test.js +8 -3
  17. package/es6/AsYouType.test.js.map +1 -1
  18. package/es6/helpers/getCountryByNationalNumber.js +17 -17
  19. package/es6/helpers/getCountryByNationalNumber.js.map +1 -1
  20. package/es6/parse.test.js +7 -3
  21. package/es6/parse.test.js.map +1 -1
  22. package/examples.mobile.json +1 -1
  23. package/examples.mobile.json.js +1 -1
  24. package/index.d.cts +54 -19
  25. package/index.d.ts +54 -19
  26. package/metadata.full.json +1 -1
  27. package/metadata.full.json.js +1 -1
  28. package/metadata.max.json +1 -1
  29. package/metadata.max.json.js +1 -1
  30. package/metadata.min.json +1 -1
  31. package/metadata.min.json.js +1 -1
  32. package/metadata.mobile.json +1 -1
  33. package/metadata.mobile.json.js +1 -1
  34. package/package.json +2 -2
  35. package/source/AsYouType.test.js +8 -3
  36. package/source/helpers/getCountryByNationalNumber.js +18 -14
  37. package/source/parse.test.js +7 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libphonenumber-js",
3
- "version": "1.11.4",
3
+ "version": "1.11.17",
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",
@@ -98,7 +98,7 @@
98
98
  "crlf": "^1.1.1",
99
99
  "cross-env": "^7.0.3",
100
100
  "istanbul": "^1.1.0-alpha.1",
101
- "libphonenumber-metadata-generator": "^1.0.1",
101
+ "libphonenumber-metadata-generator": "^1.1.0",
102
102
  "minimist": "^1.2.6",
103
103
  "mocha": "^10.0.0",
104
104
  "npm-run-all": "^4.1.5",
@@ -1380,17 +1380,22 @@ describe('AsYouType.getNumberValue()', () => {
1380
1380
  formatter.getTemplate().should.equal('xxx xxx xxx xxx')
1381
1381
  })
1382
1382
 
1383
- it('should choose `defaultCountry` (non-"main" one) when multiple countries match the number', function() {
1383
+ it('should not choose `defaultCountry` over the "main" one when both the `defaultCountry` and the "main" one match the phone number', function() {
1384
+ // This phone number matches both US and CA because they have the same
1385
+ // regular expression for some weird reason.
1384
1386
  // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103
1385
1387
  const formatter = new AsYouType('CA')
1386
1388
  formatter.input('8004001000')
1387
- formatter.getNumber().country.should.equal('CA')
1389
+ formatter.getNumber().country.should.not.equal('CA')
1390
+ formatter.getNumber().country.should.equal('US')
1388
1391
 
1392
+ // This phone number is specific to CA.
1389
1393
  const formatter2 = new AsYouType('US')
1390
1394
  formatter2.input('4389999999')
1391
1395
  formatter2.getNumber().country.should.equal('CA')
1392
1396
 
1393
- // No country matches the national number digits.
1397
+ // This phone number doesn't belong neither to CA nor to US.
1398
+ // In fact, it doesn't belong to any country from the "NANPA" zone.
1394
1399
  const formatter3 = new AsYouType('US')
1395
1400
  formatter3.input('1111111111')
1396
1401
  formatter3.getNumber().country.should.equal('US')
@@ -9,7 +9,7 @@ export default function getCountryByNationalNumber(nationalPhoneNumber, {
9
9
  // Re-create `metadata` because it will be selecting a `country`.
10
10
  metadata = new Metadata(metadata)
11
11
 
12
- const matchingCountries = []
12
+ // const matchingCountries = []
13
13
 
14
14
  for (const country of countries) {
15
15
  metadata.country(country)
@@ -29,20 +29,24 @@ export default function getCountryByNationalNumber(nationalPhoneNumber, {
29
29
  // Else perform full validation with all of those
30
30
  // fixed-line/mobile/etc regular expressions.
31
31
  else if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {
32
- // If the `defaultCountry` is among the `matchingCountries` then return it.
33
- if (defaultCountry) {
34
- if (country === defaultCountry) {
35
- return country
36
- }
37
- matchingCountries.push(country)
38
- } else {
39
- return country
40
- }
32
+ // If both the `defaultCountry` and the "main" one match the phone number,
33
+ // don't prefer the `defaultCountry` over the "main" one.
34
+ // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/154
35
+ return country
36
+ // // If the `defaultCountry` is among the `matchingCountries` then return it.
37
+ // if (defaultCountry) {
38
+ // if (country === defaultCountry) {
39
+ // return country
40
+ // }
41
+ // matchingCountries.push(country)
42
+ // } else {
43
+ // return country
44
+ // }
41
45
  }
42
46
  }
43
47
 
44
- // Return the first ("main") one of the `matchingCountries`.
45
- if (matchingCountries.length > 0) {
46
- return matchingCountries[0]
47
- }
48
+ // // Return the first ("main") one of the `matchingCountries`.
49
+ // if (matchingCountries.length > 0) {
50
+ // return matchingCountries[0]
51
+ // }
48
52
  }
@@ -546,12 +546,16 @@ describe('parse', () => {
546
546
  expect(() => parseNumber('+1123-456-7890 7777777#', { v2: true })).to.throw('NOT_A_NUMBER')
547
547
  })
548
548
 
549
- it('should choose `defaultCountry` (non-"main" one) when multiple countries match the number', () => {
549
+ it('should not choose `defaultCountry` over the "main" one when both the `defaultCountry` and the "main" one match the phone number', function() {
550
+ // This phone number matches both US and CA because they have the same
551
+ // regular expression for some weird reason.
550
552
  // https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103
551
553
  const phoneNumber = parseNumber('8004001000', { defaultCountry: 'CA', v2: true })
552
- phoneNumber.country.should.equal('CA')
554
+ phoneNumber.country.should.not.equal('CA')
555
+ phoneNumber.country.should.equal('US')
553
556
 
557
+ // This phone number is specific to CA.
554
558
  const phoneNumber2 = parseNumber('4389999999', { defaultCountry: 'US', v2: true })
555
- phoneNumber.country.should.equal('CA')
559
+ phoneNumber2.country.should.equal('CA')
556
560
  })
557
561
  })