libphonenumber-js 1.9.52 → 1.9.53

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 (44) hide show
  1. package/README.md +29 -3
  2. package/build/AsYouType.test.js +17 -2
  3. package/build/AsYouType.test.js.map +1 -1
  4. package/build/AsYouTypeFormatter.js +4 -1
  5. package/build/AsYouTypeFormatter.js.map +1 -1
  6. package/build/helpers/extractNationalNumber.js +53 -40
  7. package/build/helpers/extractNationalNumber.js.map +1 -1
  8. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -1
  9. package/build/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  10. package/build/parsePhoneNumberFromString.test.js +7 -0
  11. package/build/parsePhoneNumberFromString.test.js.map +1 -1
  12. package/bundle/libphonenumber-js.min.js +1 -1
  13. package/bundle/libphonenumber-js.min.js.map +1 -1
  14. package/bundle/libphonenumber-max.js +1 -1
  15. package/bundle/libphonenumber-max.js.map +1 -1
  16. package/bundle/libphonenumber-min.js +1 -1
  17. package/bundle/libphonenumber-min.js.map +1 -1
  18. package/bundle/libphonenumber-mobile.js +1 -1
  19. package/bundle/libphonenumber-mobile.js.map +1 -1
  20. package/es6/AsYouType.test.js +17 -2
  21. package/es6/AsYouType.test.js.map +1 -1
  22. package/es6/AsYouTypeFormatter.js +4 -1
  23. package/es6/AsYouTypeFormatter.js.map +1 -1
  24. package/es6/helpers/extractNationalNumber.js +50 -37
  25. package/es6/helpers/extractNationalNumber.js.map +1 -1
  26. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -1
  27. package/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js.map +1 -1
  28. package/es6/parsePhoneNumberFromString.test.js +7 -0
  29. package/es6/parsePhoneNumberFromString.test.js.map +1 -1
  30. package/index.d.ts +2 -2
  31. package/metadata.full.json +1 -1
  32. package/metadata.full.json.js +1 -1
  33. package/metadata.max.json +1 -1
  34. package/metadata.max.json.js +1 -1
  35. package/metadata.min.json +1 -1
  36. package/metadata.min.json.js +1 -1
  37. package/metadata.mobile.json +1 -1
  38. package/metadata.mobile.json.js +1 -1
  39. package/package.json +1 -1
  40. package/source/AsYouType.test.js +18 -2
  41. package/source/AsYouTypeFormatter.js +6 -2
  42. package/source/helpers/extractNationalNumber.js +49 -35
  43. package/source/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +1 -1
  44. package/source/parsePhoneNumberFromString.test.js +8 -0
package/README.md CHANGED
@@ -1329,7 +1329,33 @@ This package currently [doesn't provide](https://gitlab.com/catamphetamine/libph
1329
1329
 
1330
1330
  ## Bug reporting
1331
1331
 
1332
- When reporting an issue one must also provide a link to [Google's `libphonenumber` demo page](https://libphonenumber.appspot.com/) illustrating the expected behaviour. This includes validation, parsing, formatting and "as you type" formatting. For example, for an Australian number `438 331 999` Google's demo [outputs four sections](https://libphonenumber.appspot.com/phonenumberparser?number=438331999&country=AU) — "Parsing Result", "Validation Results", "Formatting Results" and "AsYouTypeFormatter Results". In a bug report, first describe the observed `libphonenumber-js` demo result and then Google's demo result (with a link to it) which must differ from the observed `libphonenumber-js` demo result. If the observed `libphonenumber-js` demo result is the same as Google's demo result and you don't agree with Google's demo result then create an issue in [Google's repo](https://github.com/googlei18n/libphonenumber).
1332
+ This library is a simpler rewrite of Google's [`libphonenumber`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/) library. Basically, it mimicks Google's library behavior. Hence, as long as this library's [demo page](https://catamphetamine.gitlab.io/libphonenumber-js/) and Google's library [demo page](https://libphonenumber.appspot.com/) exhibit the same behavior, it's not considered a bug.
1333
+
1334
+ When reporting issues with:
1335
+
1336
+ * Parsing
1337
+ * Validation
1338
+ * Formatting
1339
+ * "As You Type" formatting
1340
+
1341
+ one must provide two links:
1342
+
1343
+ * A link to the [demo page](https://catamphetamine.gitlab.io/libphonenumber-js/) illustrating the supposedly incorrect behavior.
1344
+ * A link to [Google's `libphonenumber` demo page](https://libphonenumber.appspot.com/) illustrating the expected behavior.
1345
+
1346
+ Google's demo page [outputs four sections](https://libphonenumber.appspot.com/phonenumberparser?number=438331999&country=AU):
1347
+ * "Parsing Result"
1348
+ * "Validation Results"
1349
+ * "Formatting Results"
1350
+ * "AsYouTypeFormatter Results"
1351
+
1352
+ Choose the relevant section of those four corresponding to the type of the bug you're reporting.
1353
+
1354
+ In a bug report:
1355
+
1356
+ * First, describe the observed `libphonenumber-js` demo result (and provide a link to it).
1357
+ * Second, describe the observed Google's demo result (and provide a link to it).
1358
+ * The described observed result of Google's demo must be different from the described observed result of `libphonenumber-js` demo, otherwise it's not considered a bug. If you don't agree with Google's demo result then create an issue in [Google's repo](https://github.com/google/libphonenumber/blob/master/CONTRIBUTING.md) instead. If they fix it in their library, I'll port the fix to this library.
1333
1359
 
1334
1360
  <!--
1335
1361
  Phone number validation bugs should **only** be reported if they appear when using [custom metadata functions](#customizing-metadata) fed with `metadata.max.json` because by default all functions in this library use the reduced metadata set which results in looser validation than the original Google `libphonenumber`'s. The [demo page](https://catamphetamine.gitlab.io/libphonenumber-js/) also uses the reduced metadata set and therefore its validation is also looser than the original Google `libphonenumber`'s.
@@ -1337,7 +1363,7 @@ Phone number validation bugs should **only** be reported if they appear when usi
1337
1363
  There is also a possibility of this library's demo metadata being outdated, or this library's metadata lagging behind Google's (I have to update it manually from time to time due to `ssh-agent` not working properly on Windows).
1338
1364
  -->
1339
1365
 
1340
- When reporting `findPhoneNumbersInText()` bugs one should know that `findPhoneNumbersInText()` code was ported from [Google's Java code](https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java). I didn't write it myself, I just ported it. Therefore, it is unlikely that anyone other than Google will be fixing such bugs.
1366
+ <!-- When reporting `findPhoneNumbersInText()` bugs, one should know that `findPhoneNumbersInText()` code was ported from [Google's Java code](https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java). I didn't write it myself, I just ported it. Therefore, it is unlikely that anyone other than Google would fix any bugs. -->
1341
1367
 
1342
1368
  ## TypeScript
1343
1369
 
@@ -1672,7 +1698,7 @@ Also Google sometimes (very rarely) updates their code:
1672
1698
  * [`AsYouTypeFormatter.java`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java) — `AsYouType`
1673
1699
  * [`PhoneNumberMatcher.java`](https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java) — `findPhoneNumbersInText()`
1674
1700
 
1675
- The latest sync-up was on June 7th, 2021.
1701
+ The latest sync-up was on April 24th, 2022.
1676
1702
 
1677
1703
  ## Contributing
1678
1704
 
@@ -654,8 +654,8 @@ describe('AsYouType', function () {
654
654
  // `1` is prepended before area code to mobile numbers in international format.
655
655
 
656
656
  asYouType.reset();
657
- asYouType.input('+521331234567').should.equal('+52 13 3123 4567');
658
- asYouType.getTemplate().should.equal('xxx xx xxxx xxxx'); // Google's `libphonenumber` seems to not able to format this type of number.
657
+ asYouType.input('+521331234567').should.equal('+52 133 1234 567');
658
+ asYouType.getTemplate().should.equal('xxx xxx xxxx xxx'); // Google's `libphonenumber` seems to not able to format this type of number.
659
659
  // https://issuetracker.google.com/issues/147938979
660
660
 
661
661
  asYouType.input('8').should.equal('+52 133 1234 5678');
@@ -1192,6 +1192,21 @@ describe('AsYouType.getNumberValue()', function () {
1192
1192
  formatter.input('4');
1193
1193
  expect(formatter.getNumberValue()).to.be.undefined;
1194
1194
  });
1195
+ it('should not drop any input digits', function () {
1196
+ // Test "+529011234567" number, proactively ensuring that no formatting is applied,
1197
+ // where a format is chosen that would otherwise have led to some digits being dropped.
1198
+ var formatter = new AsYouType('MX');
1199
+ formatter.input('9').should.equal('9');
1200
+ formatter.input('0').should.equal('90');
1201
+ formatter.input('1').should.equal('901');
1202
+ formatter.input('1').should.equal('901 1');
1203
+ formatter.input('2').should.equal('901 12');
1204
+ formatter.input('3').should.equal('901 123');
1205
+ formatter.input('4').should.equal('901 123 4');
1206
+ formatter.input('5').should.equal('901 123 45');
1207
+ formatter.input('6').should.equal('901 123 456');
1208
+ formatter.input('7').should.equal('901 123 4567');
1209
+ });
1195
1210
  });
1196
1211
 
1197
1212
  function type(something) {