libphonenumber-js 1.9.38 → 1.9.42
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 +10 -0
- package/README.md +8 -8
- package/build/AsYouType.test.js +25 -3
- package/build/AsYouType.test.js.map +1 -1
- package/build/AsYouTypeFormatter.PatternMatcher.js +435 -0
- package/build/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
- package/build/AsYouTypeFormatter.PatternMatcher.test.js +447 -0
- package/build/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
- package/build/AsYouTypeFormatter.js +57 -10
- package/build/AsYouTypeFormatter.js.map +1 -1
- package/build/PhoneNumber.test.js +9 -9
- package/build/PhoneNumber.test.js.map +1 -1
- package/build/findNumbers.test.js +23 -23
- package/build/findNumbers.test.js.map +1 -1
- package/build/getExampleNumber.test.js +4 -4
- package/build/getExampleNumber.test.js.map +1 -1
- package/build/getNumberType.test.js +3 -3
- package/build/getNumberType.test.js.map +1 -1
- package/build/helpers/checkNumberLength.test.js +3 -3
- package/build/helpers/checkNumberLength.test.js.map +1 -1
- package/build/helpers/extractCountryCallingCode.test.js +4 -4
- package/build/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/build/parsePhoneNumber.test.js +2 -2
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/AsYouType.test.js +25 -3
- package/es6/AsYouType.test.js.map +1 -1
- package/es6/AsYouTypeFormatter.PatternMatcher.js +428 -0
- package/es6/AsYouTypeFormatter.PatternMatcher.js.map +1 -0
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js +442 -0
- package/es6/AsYouTypeFormatter.PatternMatcher.test.js.map +1 -0
- package/es6/AsYouTypeFormatter.js +56 -10
- package/es6/AsYouTypeFormatter.js.map +1 -1
- package/es6/PhoneNumber.test.js +1 -1
- package/es6/PhoneNumber.test.js.map +1 -1
- package/es6/findNumbers.test.js +1 -1
- package/es6/findNumbers.test.js.map +1 -1
- package/es6/getExampleNumber.test.js +2 -2
- package/es6/getExampleNumber.test.js.map +1 -1
- package/es6/getNumberType.test.js +1 -1
- package/es6/getNumberType.test.js.map +1 -1
- package/es6/helpers/checkNumberLength.test.js +1 -1
- package/es6/helpers/checkNumberLength.test.js.map +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js +1 -1
- package/es6/helpers/extractCountryCallingCode.test.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +1 -1
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/exports/README.md +78 -0
- package/exports/examples.mobile.json/index.js +1 -0
- package/exports/metadata.max.json/index.js +1 -0
- package/exports/metadata.min.json/index.js +1 -0
- package/exports/metadata.mobile.json/index.js +1 -0
- package/exports/package.exports.json +55 -0
- package/max/index.commonjs.js +1 -1
- package/max/metadata.js +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -0
- package/metadata.max.json.d.ts +4 -0
- package/metadata.max.json.js +4 -0
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/package.json +4 -2
- package/source/AsYouType.test.js +26 -3
- package/source/AsYouTypeFormatter.PatternMatcher.js +343 -0
- package/source/AsYouTypeFormatter.PatternMatcher.test.js +596 -0
- package/source/AsYouTypeFormatter.js +58 -9
- package/source/PhoneNumber.test.js +1 -1
- package/source/findNumbers.test.js +1 -1
- package/source/getExampleNumber.test.js +2 -2
- package/source/getNumberType.test.js +1 -1
- package/source/helpers/checkNumberLength.test.js +1 -1
- package/source/helpers/extractCountryCallingCode.test.js +1 -1
- package/source/parsePhoneNumber.test.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -67,6 +67,16 @@ And edit the README:
|
|
|
67
67
|
|
|
68
68
|
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.
|
|
69
69
|
|
|
70
|
+
1.9.42 / 05.11.2021
|
|
71
|
+
==================
|
|
72
|
+
|
|
73
|
+
* Added a better called alias for `metadata.full.json` — `metadata.max.json`.
|
|
74
|
+
|
|
75
|
+
1.9.40 / 02.11.2021
|
|
76
|
+
==================
|
|
77
|
+
|
|
78
|
+
* Improved [format selection](https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/93) in `AsYouType` formatter: previously it chose the first one before there were at least 3 national (significant) number digits, now it starts filtering out formats right from the start of the national (significant) number.
|
|
79
|
+
|
|
70
80
|
1.9.36 / 05.10.2021
|
|
71
81
|
==================
|
|
72
82
|
|
package/README.md
CHANGED
|
@@ -283,7 +283,7 @@ findPhoneNumbersInText(`
|
|
|
283
283
|
|
|
284
284
|
This library provides different "metadata" sets, "metadata" being a list of phone number parsing and formatting rules for all countries. The complete list of those rules is huge, so this library provides a way to optimize bundle size by choosing between `max`, `min`, `mobile` and "custom" metadata:
|
|
285
285
|
|
|
286
|
-
* `max` — The complete metadata set, is about `145 kilobytes` in size (`libphonenumber-js/metadata.
|
|
286
|
+
* `max` — The complete metadata set, is about `145 kilobytes` in size (`libphonenumber-js/metadata.max.json`). Choose this when you need the most strict version of `isValid()`, or if you need to detect phone number type ("fixed line", "mobile", etc).
|
|
287
287
|
|
|
288
288
|
* `min` — (default) The smallest metadata set, is about `80 kilobytes` in size (`libphonenumber-js/metadata.min.json`). Choose this by default: when you don't need to detect phone number type ("fixed line", "mobile", etc), or when a basic version of `isValid()` is enough. The `min` metadata set doesn't contain the regular expressions for phone number digits validation (via [`.isValid()`](#isvalid)) and detecting phone number type (via [`.getType()`](#gettype)) for most countries. In this case, `.isValid()` still performs some basic phone number validation (for example, checks phone number length), but it doesn't validate phone number digits themselves the way `max` metadata validation does.
|
|
289
289
|
|
|
@@ -1285,7 +1285,7 @@ The difference between using `parseNumber()` and `isValidNumber()` for phone num
|
|
|
1285
1285
|
|
|
1286
1286
|
This is how it is implemented in the original Google's [`libphonenumber`](https://static.javadoc.io/com.googlecode.libphonenumber/libphonenumber/8.9.1/com/google/i18n/phonenumbers/PhoneNumberUtil.html#parse-java.lang.CharSequence-java.lang.String-): `parseNumber()` parses phone numbers and loosely validates them while `isValidNumber()` validates phone numbers precisely (provided the precise regular expressions are included in metadata).
|
|
1287
1287
|
|
|
1288
|
-
The precise regular expressions aren't included in the default metadata because that would cause the default metadata to grow twice in its size: the complete ("full") metadata size is about 145 kilobytes while the reduced ("default") metadata size is about 77 kilobytes. Hence in the default configuration `isValidNumber()` performs absolutely the same "lite" validation as `parseNumber()`. For enabling extensive phone number validation the simplest way is to import functions from `libphonenumber-js/custom` module and supply them with `libphonenumber-js/metadata.
|
|
1288
|
+
The precise regular expressions aren't included in the default metadata because that would cause the default metadata to grow twice in its size: the complete ("full") metadata size is about 145 kilobytes while the reduced ("default") metadata size is about 77 kilobytes. Hence in the default configuration `isValidNumber()` performs absolutely the same "lite" validation as `parseNumber()`. For enabling extensive phone number validation the simplest way is to import functions from `libphonenumber-js/custom` module and supply them with `libphonenumber-js/metadata.max.json`. For generating custom metadata see the instructions provided in the [Customizing metadata](#customizing-metadata) section of this document.
|
|
1289
1289
|
</details>
|
|
1290
1290
|
|
|
1291
1291
|
####
|
|
@@ -1324,7 +1324,7 @@ If you’re trying to build a React component with this library, take a look at
|
|
|
1324
1324
|
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).
|
|
1325
1325
|
|
|
1326
1326
|
<!--
|
|
1327
|
-
Phone number validation bugs should **only** be reported if they appear when using [custom metadata functions](#customizing-metadata) fed with `metadata.
|
|
1327
|
+
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.
|
|
1328
1328
|
|
|
1329
1329
|
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).
|
|
1330
1330
|
-->
|
|
@@ -1423,7 +1423,7 @@ Using with custom metadata:
|
|
|
1423
1423
|
import { Metadata } from 'libphonenumber-js/core'
|
|
1424
1424
|
|
|
1425
1425
|
import min from 'libphonenumber-js/metadata.min.json'
|
|
1426
|
-
// import max from 'libphonenumber-js/metadata.
|
|
1426
|
+
// import max from 'libphonenumber-js/metadata.max.json'
|
|
1427
1427
|
// import mobile from 'libphonenumber-js/metadata.mobile.json'
|
|
1428
1428
|
|
|
1429
1429
|
const metadata = new Metadata(min)
|
|
@@ -1471,7 +1471,7 @@ import _parsePhoneNumber, {
|
|
|
1471
1471
|
AsYouType as _AsYouType
|
|
1472
1472
|
} from 'libphonenumber-js/core'
|
|
1473
1473
|
|
|
1474
|
-
import metadata from 'libphonenumber-js/metadata.
|
|
1474
|
+
import metadata from 'libphonenumber-js/metadata.max.json'
|
|
1475
1475
|
|
|
1476
1476
|
function call(func, _arguments) {
|
|
1477
1477
|
var args = Array.prototype.slice.call(_arguments)
|
|
@@ -1498,7 +1498,7 @@ And for [Common.js](https://auth0.com/blog/javascript-module-systems-showdown/)
|
|
|
1498
1498
|
|
|
1499
1499
|
```js
|
|
1500
1500
|
var core = require('libphonenumber-js/core')
|
|
1501
|
-
var metadata = require('libphonenumber-js/metadata.
|
|
1501
|
+
var metadata = require('libphonenumber-js/metadata.max.json')
|
|
1502
1502
|
|
|
1503
1503
|
function call(func, _arguments) {
|
|
1504
1504
|
var args = Array.prototype.slice.call(_arguments)
|
|
@@ -1545,7 +1545,7 @@ import {
|
|
|
1545
1545
|
AsYouType
|
|
1546
1546
|
} from 'libphonenumber-js/custom'
|
|
1547
1547
|
|
|
1548
|
-
import metadata from 'libphonenumber-js/metadata.
|
|
1548
|
+
import metadata from 'libphonenumber-js/metadata.max.json'
|
|
1549
1549
|
|
|
1550
1550
|
parseNumber('+78005553535', metadata)
|
|
1551
1551
|
formatNumber({ phone: '8005553535', country: 'RU' }, metadata)
|
|
@@ -1558,7 +1558,7 @@ And for [Common.js](https://auth0.com/blog/javascript-module-systems-showdown/)
|
|
|
1558
1558
|
|
|
1559
1559
|
```js
|
|
1560
1560
|
var custom = require('libphonenumber-js/custom')
|
|
1561
|
-
var metadata = require('libphonenumber-js/metadata.
|
|
1561
|
+
var metadata = require('libphonenumber-js/metadata.max.json')
|
|
1562
1562
|
|
|
1563
1563
|
exports.parseNumber = function parseNumber() {
|
|
1564
1564
|
var parameters = Array.prototype.slice.call(arguments)
|
package/build/AsYouType.test.js
CHANGED
|
@@ -487,14 +487,27 @@ describe('AsYouType', function () {
|
|
|
487
487
|
// (contains national prefix in an international phone number)
|
|
488
488
|
|
|
489
489
|
formatter.reset();
|
|
490
|
-
formatter.input('+1-1');
|
|
490
|
+
formatter.input('+1-1'); // Before leading digits < 3 matching was implemented:
|
|
491
|
+
//
|
|
492
|
+
// phoneNumber = formatter.getNumber()
|
|
493
|
+
// expect(phoneNumber).to.not.be.undefined
|
|
494
|
+
//
|
|
495
|
+
// formatter.input('1')
|
|
496
|
+
// phoneNumber = formatter.getNumber()
|
|
497
|
+
// expect(phoneNumber.country).to.be.undefined
|
|
498
|
+
// phoneNumber.countryCallingCode.should.equal('1')
|
|
499
|
+
// phoneNumber.number.should.equal('+111')
|
|
500
|
+
// After leading digits < 3 matching was implemented:
|
|
501
|
+
//
|
|
502
|
+
|
|
491
503
|
phoneNumber = formatter.getNumber();
|
|
492
|
-
expect(phoneNumber).to.
|
|
504
|
+
expect(phoneNumber).to.be.undefined; //
|
|
505
|
+
|
|
493
506
|
formatter.input('1');
|
|
494
507
|
phoneNumber = formatter.getNumber();
|
|
495
508
|
expect(phoneNumber.country).to.be.undefined;
|
|
496
509
|
phoneNumber.countryCallingCode.should.equal('1');
|
|
497
|
-
phoneNumber.number.should.equal('+
|
|
510
|
+
phoneNumber.number.should.equal('+11');
|
|
498
511
|
});
|
|
499
512
|
it('should work with countries that add digits to national (significant) number', function () {
|
|
500
513
|
// When formatting Argentinian mobile numbers in international format,
|
|
@@ -585,6 +598,15 @@ describe('AsYouType', function () {
|
|
|
585
598
|
|
|
586
599
|
formatter.isPossible().should.equal(true);
|
|
587
600
|
formatter.isValid().should.equal(true);
|
|
601
|
+
}); // https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/93
|
|
602
|
+
|
|
603
|
+
it('should format Indonesian numbers', function () {
|
|
604
|
+
var formatter = new AsYouType('ID');
|
|
605
|
+
formatter.getChars().should.equal(''); // Before leading digits < 3 matching was implemented:
|
|
606
|
+
// formatter.input('081').should.equal('(081)')
|
|
607
|
+
// After leading digits < 3 matching was implemented:
|
|
608
|
+
|
|
609
|
+
formatter.input('081').should.equal('081');
|
|
588
610
|
});
|
|
589
611
|
it('should prepend `complexPrefixBeforeNationalSignificantNumber` (not a complete number)', function () {
|
|
590
612
|
// A country having `national_prefix_for_parsing` with a "capturing group".
|