libphonenumber-js 1.9.19 → 1.9.23

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 (49) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +63 -3
  3. package/build/AsYouType.test.js +8 -7
  4. package/build/AsYouType.test.js.map +1 -1
  5. package/build/PhoneNumber.js +4 -0
  6. package/build/PhoneNumber.js.map +1 -1
  7. package/build/PhoneNumber.test.js +3 -0
  8. package/build/PhoneNumber.test.js.map +1 -1
  9. package/build/format.test.js +7 -0
  10. package/build/format.test.js.map +1 -1
  11. package/build/helpers/getIddPrefix.js +4 -2
  12. package/build/helpers/getIddPrefix.js.map +1 -1
  13. package/build/parse.test.js +3 -3
  14. package/build/parse.test.js.map +1 -1
  15. package/bundle/libphonenumber-js.min.js +1 -1
  16. package/bundle/libphonenumber-js.min.js.map +1 -1
  17. package/bundle/libphonenumber-max.js +1 -1
  18. package/bundle/libphonenumber-max.js.map +1 -1
  19. package/bundle/libphonenumber-min.js +1 -1
  20. package/bundle/libphonenumber-min.js.map +1 -1
  21. package/bundle/libphonenumber-mobile.js +1 -1
  22. package/bundle/libphonenumber-mobile.js.map +1 -1
  23. package/es6/AsYouType.test.js +8 -7
  24. package/es6/AsYouType.test.js.map +1 -1
  25. package/es6/PhoneNumber.js +4 -0
  26. package/es6/PhoneNumber.js.map +1 -1
  27. package/es6/PhoneNumber.test.js +3 -0
  28. package/es6/PhoneNumber.test.js.map +1 -1
  29. package/es6/format.test.js +7 -0
  30. package/es6/format.test.js.map +1 -1
  31. package/es6/helpers/getIddPrefix.js +4 -2
  32. package/es6/helpers/getIddPrefix.js.map +1 -1
  33. package/es6/parse.test.js +3 -3
  34. package/es6/parse.test.js.map +1 -1
  35. package/metadata.full.json +1 -1
  36. package/metadata.full.json.js +1 -1
  37. package/metadata.min.json +1 -1
  38. package/metadata.min.json.js +1 -1
  39. package/metadata.mobile.json +1 -1
  40. package/metadata.mobile.json.js +1 -1
  41. package/package.json +1 -1
  42. package/runnable/metadata-update-and-push-and-pull-request.js +1 -1
  43. package/runnable/modules/commit.js +1 -1
  44. package/source/AsYouType.test.js +8 -6
  45. package/source/PhoneNumber.js +3 -0
  46. package/source/PhoneNumber.test.js +1 -0
  47. package/source/format.test.js +6 -0
  48. package/source/helpers/getIddPrefix.js +3 -1
  49. package/source/parse.test.js +3 -3
package/CHANGELOG.md CHANGED
@@ -71,6 +71,13 @@ And edit the README:
71
71
 
72
72
  <!-- (breaking change) Changed `countries` and `country_calling_codes` properties in metadata: now they're not properties but rather elements of an array (`countries` is an array now rather than an object; `countries` is `metadata[0]` and `country_calling_codes` is `metadata[1]`). If you were using a custom-generated metadata then it has to be re-generated for the new version. -->
73
73
 
74
+ This changelog [only](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/16#note_594165443) mentions the changes in the code. See [Google's changelog](https://github.com/google/libphonenumber/blob/master/release_notes.txt) for metadata changes.
75
+
76
+ 1.9.20 / 07.06.2021
77
+ ==================
78
+
79
+ * [Changed](https://github.com/google/libphonenumber/commit/c6277266fba8223cfc610cfb1e999deb9f876d65) formatting numbers in `IDD` format to always use the preferred IDD prefix (if defined), not just in cases when a country has multiple IDD prefixes. This means that it will output `8~10` as the prefix instead of `810` for some regions (like Uzbekistan) that have this tilde in their IDD prefix (the tilde designates that the user should wait before continuing to dial).
80
+
74
81
  1.9.11 / 10.02.2021
75
82
  ==================
76
83
 
package/README.md CHANGED
@@ -40,7 +40,7 @@ One part of me was curious about how all this phone number parsing and formattin
40
40
 
41
41
  * "Two-in-one" phone numbers with "combined" extensions like `(530) 583-6985 x302/x2303` that in fact represent two separate phone numbers, because the library can only return a single phone number when parsing a string.
42
42
 
43
- * Overall, doesn't support formatting non-"conventional" numbers like numbers with the "area code" omitted. When dialing phone numbers within the same "area", people sometimes skip the "area code", and dial, for example, `456-789` instead of `(123) 456-789`. Google's `libphonenumber` supports formatting such numbers (with "area code" omitted) because it is used for dialing on the Android phone operating system. Because `libphonenumber-js` isn't a phone operating system and it's not used for dialing, it doesn't format such "shortened" phone numbers.
43
+ * Overall, doesn't support formatting non-"conventional" numbers like numbers with the "area code" omitted or "alternative" "short" numbers like [Australian `13`-smart numbers](https://github.com/catamphetamine/libphonenumber-js/issues/400). For example, when dialing phone numbers within the same "area", people sometimes skip the "area code", and dial, say, `456-789` instead of `(123) 456-789`. Google's `libphonenumber` supports formatting such numbers (with "area code" omitted) because it is used for dialing on the Android phone operating system. Because `libphonenumber-js` isn't a phone operating system and is not used for actual dialing — only for inputting internationally-dialable personal phone numbers — it doesn't format such "short" phone numbers because it doesn't need to support those.
44
44
 
45
45
  * Any other "miscellaneous" cases that're considered irrelevant for the task.
46
46
 
@@ -90,6 +90,55 @@ If you're not using a bundler then use a [standalone version from a CDN](https:/
90
90
 
91
91
  ## Use
92
92
 
93
+ <!--
94
+ ### Importing
95
+
96
+ When using [Babel](https://babeljs.io/) or [`esm`](npmjs.com/package/esm) or [rollup.js](https://rollupjs.org/) or any other `import` transpiler:
97
+
98
+ ```js
99
+ import parsePhoneNumber, {
100
+ isPossiblePhoneNumber,
101
+ isValidPhoneNumber,
102
+ AsYouType,
103
+ findPhoneNumbersInText
104
+ } from 'libphonenumber-js'
105
+ ```
106
+
107
+ When using Node.js 14 and not using any of the above:
108
+
109
+ ```js
110
+ import parsePhoneNumber from 'libphonenumber-js'
111
+
112
+ // or
113
+
114
+ import libphonenumber from 'libphonenumber-js'
115
+
116
+ const {
117
+ default: parsePhoneNumber,
118
+ isPossiblePhoneNumber,
119
+ isValidPhoneNumber,
120
+ AsYouType,
121
+ findPhoneNumbersInText
122
+ } = libphonenumber
123
+ ```
124
+
125
+ When using Node.js < 14 and not using any of the above:
126
+
127
+ ```js
128
+ const libphonenumber = require('libphonenumber-js')
129
+
130
+ const {
131
+ default: parsePhoneNumber,
132
+ isPossiblePhoneNumber,
133
+ isValidPhoneNumber,
134
+ AsYouType,
135
+ findPhoneNumbersInText
136
+ } = libphonenumber
137
+ ```
138
+
139
+ https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/42
140
+ -->
141
+
93
142
  ### Parse phone number
94
143
 
95
144
  <!--
@@ -1502,7 +1551,13 @@ Google periodically releases new metadata with the changes described in the [rel
1502
1551
 
1503
1552
  Metadata update process is automated through an "autoupdate" script: see `autoupdate.cmd` (Windows) or `autoupdate.sh` (Linux/macOS). The script detects changes to `PhoneNumberMetadata.xml` in Google `libphonenumber`'s repo and if there are changes then it pulls the latest metadata, processes it, commits the changes to GitHub, builds a new version of the library and releases it to NPM. So this library's metadata is supposed to be up-to-date. I could set up this script to run automatically but on my Windows machine `ssh-agent` doesn't work properly so I run the "autoupdate" script manually from time to time.
1504
1553
 
1505
- Also Google sometimes (very rarely) updates their code: [`phonenumberutil.js`](https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js) (`parseNumber()`, `formatNumber()`, `isValidNumber()`, `getNumberType()`), [`AsYouTypeFormatter.java`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java) (`AsYouType`), [`PhoneNumberMatcher`](https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java) (`findPhoneNumbersInText()`). The latest sync-up was performed on Jan 28th, 2021.
1554
+ Also Google sometimes (very rarely) updates their code:
1555
+
1556
+ * [`phonenumberutil.js`](https://github.com/googlei18n/libphonenumber/blob/master/javascript/i18n/phonenumbers/phonenumberutil.js) — `parseNumber()`, `formatNumber()`, `isValidNumber()`, `getNumberType()`
1557
+ * [`AsYouTypeFormatter.java`](https://github.com/google/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java) — `AsYouType`
1558
+ * [`PhoneNumberMatcher.java`](https://github.com/googlei18n/libphonenumber/blob/master/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java) — `findPhoneNumbersInText()`
1559
+
1560
+ The latest sync-up was on June 7th, 2021.
1506
1561
 
1507
1562
  ## Contributing
1508
1563
 
@@ -1552,4 +1607,9 @@ If you're looking for an international "2 days ago" javascript solution then che
1552
1607
 
1553
1608
  ## License
1554
1609
 
1555
- [MIT](LICENSE)
1610
+ Google's `libphonenumber` is [licensed](https://github.com/google/libphonenumber/blob/master/LICENSE) under Apache 2.
1611
+
1612
+ [Apache 2](https://en.wikipedia.org/wiki/Apache_License#Licensing_conditions) does not require a derivative work of the software, or modifications to the original, to be distributed using the same license. Hence, this library is licensed under [MIT](LICENSE), which is [compatible](https://www.quora.com/Is-the-MIT-license-compatible-with-the-Apache-License-Version-2-APLv2) with Apache 2.
1613
+
1614
+ The Apache license is terminated if the user sues anyone over patent infringement related to the software covered by the license. This condition is added in order to prevent patent litigations.
1615
+
@@ -319,11 +319,12 @@ describe('AsYouType', function () {
319
319
  formatter = new AsYouType();
320
320
  formatter.input('+1 1 877 215 5230').should.equal('+1 1 877 215 5230'); // formatter.input('+1 1 877 215 5230').should.equal('+1 1 8772155230')
321
321
 
322
- formatter.getNationalNumber().should.equal('8772155230');
323
- formatter = new AsYouType();
324
- formatter.input('+78800555353').should.equal('+7 880 055 53 53');
325
- formatter.input('5').should.equal('+7 8 800 555 35 35');
326
- formatter.getNationalNumber().should.equal('8005553535');
322
+ formatter.getNationalNumber().should.equal('8772155230'); // They've added another number format that has `8` leading digit
323
+ // and 14 digits. Maybe it's something related to Kazakhstan.
324
+ // formatter = new AsYouType()
325
+ // formatter.input('+78800555353').should.equal('+7 880 055 53 53')
326
+ // formatter.input('5').should.equal('+7 8 800 555 35 35')
327
+ // formatter.getNationalNumber().should.equal('8005553535')
327
328
  });
328
329
  it('should return a partial template for current value', function () {
329
330
  var asYouType = new AsYouType('US');
@@ -815,10 +816,10 @@ describe('AsYouType', function () {
815
816
  });
816
817
  it('shouldn\'t choose a format when there\'re too many digits for any of them', function () {
817
818
  var formatter = new AsYouType('RU');
818
- formatter.input('88005553535');
819
+ formatter.input('89991112233');
819
820
  formatter.formatter.chosenFormat.format().should.equal('$1 $2-$3-$4');
820
821
  formatter.reset();
821
- formatter.input('880055535355');
822
+ formatter.input('899911122334');
822
823
  expect(formatter.formatter.chosenFormat).to.be.undefined;
823
824
  });
824
825
  it('should get separator after national prefix', function () {