libphonenumber-js 1.12.18 → 1.12.21
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 +38 -2
- package/README.md +53 -14
- package/build/isPossible.test.js +2 -0
- package/build/isPossible.test.js.map +1 -1
- package/build/isPossiblePhoneNumber.test.js +2 -0
- package/build/isPossiblePhoneNumber.test.js.map +1 -1
- package/build/parsePhoneNumber.test.js +3 -0
- package/build/parsePhoneNumber.test.js.map +1 -1
- package/build-scripts/check-for-metadata-changes-and-release.js +58 -8
- package/build-scripts/check-for-uncommitted-files.js +11 -0
- package/build-scripts/helpers/getUncommittedChanges.js +33 -0
- package/build-scripts/helpers/update-metadata-from-google-metadata.js +1 -1
- package/es6/isPossible.test.js +2 -0
- package/es6/isPossible.test.js.map +1 -1
- package/es6/isPossiblePhoneNumber.test.js +2 -0
- package/es6/isPossiblePhoneNumber.test.js.map +1 -1
- package/es6/parsePhoneNumber.test.js +3 -0
- package/es6/parsePhoneNumber.test.js.map +1 -1
- package/package.json +3 -2
- package/source/isPossible.test.js +2 -0
- package/source/isPossiblePhoneNumber.test.js +2 -0
- package/source/parsePhoneNumber.test.js +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -67,8 +67,44 @@ 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
|
-
<!-- CHANGELOG START -->
|
|
71
|
-
|
|
70
|
+
<!-- CHANGELOG START -->
|
|
71
|
+
|
|
72
|
+
1.12.21 / 23.9.2025
|
|
73
|
+
===================
|
|
74
|
+
|
|
75
|
+
* Updated metadata to version 9.0.14:
|
|
76
|
+
- Updated phone metadata for region code(s): CZ, DE, IT, LI, LV, ME, SG, US
|
|
77
|
+
- Updated short number metadata for region code(s): DE
|
|
78
|
+
- New geocoding data for country calling code(s): 1686 (en)
|
|
79
|
+
- Updated geocoding data for country calling code(s): 39 (en, it), 61 (en)
|
|
80
|
+
- Updated carrier data for country calling code(s):
|
|
81
|
+
46 (en), 65 (en), 420 (en), 998 (en)
|
|
82
|
+
- Updated / refreshed time zone meta data.
|
|
83
|
+
|
|
84
|
+
1.12.20 / 23.9.2025
|
|
85
|
+
===================
|
|
86
|
+
|
|
87
|
+
* Updated metadata to version 9.0.14:
|
|
88
|
+
- Updated phone metadata for region code(s): CZ, DE, IT, LI, LV, ME, SG, US
|
|
89
|
+
- Updated short number metadata for region code(s): DE
|
|
90
|
+
- New geocoding data for country calling code(s): 1686 (en)
|
|
91
|
+
- Updated geocoding data for country calling code(s): 39 (en, it), 61 (en)
|
|
92
|
+
- Updated carrier data for country calling code(s):
|
|
93
|
+
46 (en), 65 (en), 420 (en), 998 (en)
|
|
94
|
+
- Updated / refreshed time zone meta data.
|
|
95
|
+
|
|
96
|
+
1.12.19 / 23.9.2025
|
|
97
|
+
===================
|
|
98
|
+
|
|
99
|
+
* Updated metadata to version 9.0.14:
|
|
100
|
+
- Updated phone metadata for region code(s): CZ, DE, IT, LI, LV, ME, SG, US
|
|
101
|
+
- Updated short number metadata for region code(s): DE
|
|
102
|
+
- New geocoding data for country calling code(s): 1686 (en)
|
|
103
|
+
- Updated geocoding data for country calling code(s): 39 (en, it), 61 (en)
|
|
104
|
+
- Updated carrier data for country calling code(s):
|
|
105
|
+
46 (en), 65 (en), 420 (en), 998 (en)
|
|
106
|
+
- Updated / refreshed time zone meta data.
|
|
107
|
+
|
|
72
108
|
1.12.17 / 12.9.2025
|
|
73
109
|
===================
|
|
74
110
|
|
package/README.md
CHANGED
|
@@ -72,12 +72,10 @@ One part of me was curious about how all this phone number parsing and formattin
|
|
|
72
72
|
(`.formatNumberForMobileDialing()` method is not implemented therefore there's no need to format carrier codes)
|
|
73
73
|
-->
|
|
74
74
|
|
|
75
|
-
## GitHub
|
|
75
|
+
## GitHub Repository Status
|
|
76
76
|
|
|
77
77
|
On March 9th, 2020, GitHub, Inc. silently [banned](https://medium.com/@catamphetamine/how-github-blocked-me-and-all-my-libraries-c32c61f061d3) my account — erasing all my repos, issues and comments, even in my employer's private repos — without any notice or explanation. Because of that, all source codes had to be promptly moved to GitLab. The [GitHub repo](https://github.com/catamphetamine/libphonenumber-js) is now only used as a backup (although you can still "star" it), and the primary repo is now the [GitLab one](https://gitlab.com/catamphetamine/libphonenumber-js). For users' convenience, issues can be reported in both places.
|
|
78
78
|
|
|
79
|
-
If you're about to report an issue, see [bug reporting](#bug-reporting) instructions.
|
|
80
|
-
|
|
81
79
|
## Install
|
|
82
80
|
|
|
83
81
|
via [npm](https://npmjs.org/)
|
|
@@ -96,6 +94,8 @@ Alternatively, one could include it on a web page [directly](#cdn) via a `<scrip
|
|
|
96
94
|
|
|
97
95
|
## Use
|
|
98
96
|
|
|
97
|
+
If you'd like to create an issue, see [bug reporting](#bug-reporting) instructions.
|
|
98
|
+
|
|
99
99
|
<!--
|
|
100
100
|
### Importing
|
|
101
101
|
|
|
@@ -331,7 +331,7 @@ Choose one from the above and then simply `import` the functions from the releva
|
|
|
331
331
|
* `max` — `libphonenumber-js/max`
|
|
332
332
|
* `mobile` — `libphonenumber-js/mobile`
|
|
333
333
|
|
|
334
|
-
As for "custom" metadata, it could be used in those rare cases when not all countries are needed and a developer would really prefer to reduce the bundle size to a minimum. In that case, one could
|
|
334
|
+
As for "custom" metadata, it could be used in those rare cases when not all countries are needed and a developer would really prefer to reduce the bundle size to a minimum. In that case, one could generate their own ["custom"](#custom-metadata) metadata set and then `import` the functions from `libphonenumber-js/core` sub-package which doesn't come pre-packaged with any metadata and instead accepts `metadata` as the last argument of each exported function.
|
|
335
335
|
|
|
336
336
|
## Definitions
|
|
337
337
|
|
|
@@ -1454,11 +1454,11 @@ isValidNumber({ phone: '2133734253', country: 'US' }) === true
|
|
|
1454
1454
|
<details>
|
|
1455
1455
|
<summary>The difference between using <code>parseNumber()</code> and <code>isValidNumber()</code></summary>
|
|
1456
1456
|
|
|
1457
|
-
The difference between using `parseNumber()` and `isValidNumber()` for phone number validation is that `isValidNumber()` also checks the precise regular expressions of possible phone numbers for a country. For example, for Germany `parseNumber('123456', 'DE')` would return `{ country: 'DE', phone: '123456' }` because this phone number matches the general phone number rules for Germany (basic length check, etc). But, if the metadata is compiled with `--extended` (or relevant `--types`) flag (see [
|
|
1457
|
+
The difference between using `parseNumber()` and `isValidNumber()` for phone number validation is that `isValidNumber()` also checks the precise regular expressions of possible phone numbers for a country. For example, for Germany `parseNumber('123456', 'DE')` would return `{ country: 'DE', phone: '123456' }` because this phone number matches the general phone number rules for Germany (basic length check, etc). But, if the metadata is compiled with `--extended` (or relevant `--types`) flag (see [Custom metadata](#custom-metadata) section of this document) then `isValidNumber()` is gonna use those precise regular expressions for extensive validation and `isValid('123456', 'DE')` will return `false` because the phone number `123456` doesn't actually exist in Germany.
|
|
1458
1458
|
|
|
1459
1459
|
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).
|
|
1460
1460
|
|
|
1461
|
-
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 [
|
|
1461
|
+
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 [Custom metadata](#custom-metadata) section of this document.
|
|
1462
1462
|
</details>
|
|
1463
1463
|
|
|
1464
1464
|
####
|
|
@@ -1531,7 +1531,7 @@ When writing a bug report:
|
|
|
1531
1531
|
* 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 [report it to Google](https://github.com/google/libphonenumber/blob/master/CONTRIBUTING.md) directly instead. If they fix it in their library, I'll port the fix to this library.
|
|
1532
1532
|
|
|
1533
1533
|
<!--
|
|
1534
|
-
Phone number validation bugs should **only** be reported if they appear when using [custom metadata functions](#
|
|
1534
|
+
Phone number validation bugs should **only** be reported if they appear when using [custom metadata functions](#custom-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.
|
|
1535
1535
|
|
|
1536
1536
|
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).
|
|
1537
1537
|
-->
|
|
@@ -1648,10 +1648,10 @@ In case I forget to run the "autoupdate" script for a long time anyone can reque
|
|
|
1648
1648
|
|
|
1649
1649
|
`npm run metadata:update:branch` command creates a new `update-metadata` branch, downloads the new [`PhoneNumberMetadata.xml`](https://github.com/googlei18n/libphonenumber/blob/master/resources/PhoneNumberMetadata.xml) into the project folder replacing the old one, generates JSON metadata out of the XML one, checks if the metadata has changed, runs the tests, commits the new metadata and pushes the commit to the remote `update-metadata` branch of your fork.
|
|
1650
1650
|
|
|
1651
|
-
Alternatively, a developer may wish to update metadata urgently, without waiting for a pull request approval. In this case just perform the steps described in the [
|
|
1651
|
+
Alternatively, a developer may wish to update metadata urgently, without waiting for a pull request approval. In this case just perform the steps described in the [Custom metadata](#customi-metadata) section of this document.
|
|
1652
1652
|
-->
|
|
1653
1653
|
|
|
1654
|
-
###
|
|
1654
|
+
### Custom metadata
|
|
1655
1655
|
|
|
1656
1656
|
This library comes prepackaged with [three types of metadata](#min-vs-max-vs-mobile-vs-core).
|
|
1657
1657
|
|
|
@@ -1857,17 +1857,56 @@ launchctl list | grep 'libphonenumber-js'
|
|
|
1857
1857
|
```
|
|
1858
1858
|
-->
|
|
1859
1859
|
|
|
1860
|
-
|
|
1860
|
+
## Maintenance
|
|
1861
1861
|
|
|
1862
|
-
Google periodically
|
|
1862
|
+
This library reuses Google's metadata. Google periodically publishes a new version of the metadata, with the changes described in their [release notes](https://github.com/googlei18n/libphonenumber/blob/master/release_notes.txt). Those're usually minor fixes whenever some country decides to adjust their telephone numbering plan.
|
|
1863
1863
|
|
|
1864
|
-
After Google
|
|
1864
|
+
After Google updates their metadata, this library pulls the updated metadata from Google's repository and publishes a new version of itself on `npm`.
|
|
1865
1865
|
|
|
1866
1866
|
The metadata pulling process is automated through an "autoupdate" script: see `autoupdate.cmd` (Windows) or `autoupdate.sh` (Linux/macOS). The script detects changes to `PhoneNumberMetadata.xml` file in Google `libphonenumber`'s repo and, if there are any changes, it pulls the latest metadata, transforms it, commits the changes to the repository, builds a new version of the package and releases it to `npm`.
|
|
1867
1867
|
|
|
1868
|
-
I did
|
|
1868
|
+
I did manage to set up the autoupdate script to run dialy on my Windows machine in an automatic fashion through "Task Scheduler", but then `npm` started requiring "two-factor authentication" in order to publish a package, which requires human intervention, so currently the autoupdate process is kinda semi-automatic.
|
|
1869
|
+
|
|
1870
|
+
<details>
|
|
1871
|
+
<summary>How to set up <code>autoupdate.cmd</code> to run automatically on Windows</summary>
|
|
1872
|
+
|
|
1873
|
+
######
|
|
1874
|
+
|
|
1875
|
+
To set up a task to run the autoupdate script periodically in Windows:
|
|
1876
|
+
|
|
1877
|
+
* Open "Start" menu
|
|
1878
|
+
* Enter "Task Scheduler"
|
|
1879
|
+
* Task Scheduler window opens
|
|
1880
|
+
* On the right side, choose "Create Basic Task"
|
|
1881
|
+
* Enter "Name": "libphonenumber-js"
|
|
1882
|
+
* Enter some "Description"
|
|
1883
|
+
* Choose "Daily"
|
|
1884
|
+
* In "Start" specify a specific time. For example, when you're not using the computer but it's still on.
|
|
1885
|
+
* "Action" — "Start a program"
|
|
1886
|
+
* "Program/Script" — Choose the "autoupdate.cmd" file in `libphonenumber-js` directory
|
|
1887
|
+
|
|
1888
|
+
After the task has been created, go to its "Properties", select "Settings" tab and check the check box where it says "Run task as soon as possible after a scheduled start is missed".
|
|
1889
|
+
|
|
1890
|
+
Also, by default, it will open a physical "cmd" window when running the script. To prevent that, go to the task's "Properties", select "General" tab, and in "Security options" section, change the selected "radio button" from "Run only when user is logged on" to "Run whether user is logged on or not" and also check a checkbox next to it that says "Do not store password. The task will only have access to local computer resources".
|
|
1891
|
+
|
|
1892
|
+
How to [fix](https://stackoverflow.com/questions/370030/why-git-cant-remember-my-passphrase-under-windows) `git` command asking for a password every time: "Git: "Enter passphrase for key ..."":
|
|
1893
|
+
|
|
1894
|
+
* Open Windows start menu. Enter "Services". Choose the "Services" app.
|
|
1895
|
+
* In the "Services" app, find "OpenSSH Authentication Agent" service. Right-click it and choose "Properties".
|
|
1896
|
+
* In the properties modal, in the "Startup type" selector choose "Automatic". Also find and click the "Start" button below the selector. Click "OK" to close the properties modal.
|
|
1897
|
+
* Open Windows start menu. Enter "cmd". Choose the "Command Prompt" app.
|
|
1898
|
+
* Enter "ssh-add" and press Enter.
|
|
1899
|
+
* It will prompt for a passphrase: "Enter passphrase for ...". If instead it says "Error connecting to agent" then you didn't click the "Start" button at the previous steps.
|
|
1900
|
+
* Enter the passphrase and press Enter.
|
|
1901
|
+
* It will say: "Identity added".
|
|
1902
|
+
* Enter command: git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
|
|
1903
|
+
* Press Enter.
|
|
1904
|
+
* Now "git bash" is supposed to know the passphrase without having to type it in every time.
|
|
1905
|
+
</details>
|
|
1906
|
+
|
|
1907
|
+
######
|
|
1869
1908
|
|
|
1870
|
-
So I just run the "autoupdate" script manually from time to time. With this workflow, one can see how the metadata could potentially get a bit stale, in which case just ping me to re-run the autoupdate script, assuming I'm still alive and well.
|
|
1909
|
+
<!-- So currently, I just run the "autoupdate" script manually from time to time. With this workflow, one can see how the metadata could potentially get a bit stale, in which case just ping me to re-run the autoupdate script, assuming I'm still alive and well. -->
|
|
1871
1910
|
|
|
1872
1911
|
Also Google sometimes (extremely rarely) updates their code:
|
|
1873
1912
|
|
package/build/isPossible.test.js
CHANGED
|
@@ -107,6 +107,8 @@ describe('isPossible', function () {
|
|
|
107
107
|
}).to["throw"]('Unknown country');
|
|
108
108
|
});
|
|
109
109
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', function () {
|
|
110
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
111
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
110
112
|
var phoneNumber = (0, _parsePhoneNumber["default"])('+13100000', undefined, _metadataMin["default"]);
|
|
111
113
|
expect(phoneNumber.country).to.equal('CA');
|
|
112
114
|
expect(phoneNumber.isPossible()).to.equal(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPossible.test.js","names":["_metadataMin","_interopRequireDefault","require","_isPossible","_parsePhoneNumber","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","ownKeys","r","t","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","toPrimitive","call","TypeError","String","Number","isPossibleNumber","v2","_len","parameters","Array","_key","undefined","parsePhoneNumber","extract","metadata","_isPossibleNumber","describe","it","expect","to","equal","phone","country","countryCallingCode","nationalNumber","phoneNumber","isPossible","isValid"],"sources":["../source/isPossible.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' with { type: 'json' }\r\nimport _isPossibleNumber from './isPossible.js'\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nfunction isPossibleNumber(...parameters) {\r\n\tlet v2\r\n\tif (parameters.length < 1) {\r\n\t\t// `input` parameter.\r\n\t\tparameters.push(undefined)\r\n\t} else {\r\n\t\t// Convert string `input` to a `PhoneNumber` instance.\r\n\t\tif (typeof parameters[0] === 'string') {\r\n\t\t\tv2 = true\r\n\t\t\tparameters[0] = parsePhoneNumber(parameters[0], {\r\n\t\t\t\t...parameters[1],\r\n\t\t\t\textract: false\r\n\t\t\t}, metadata)\r\n\t\t}\r\n\t}\r\n\tif (parameters.length < 2) {\r\n\t\t// `options` parameter.\r\n\t\tparameters.push(undefined)\r\n\t}\r\n\t// Set `v2` flag.\r\n\tparameters[1] = {\r\n\t\tv2,\r\n\t\t...parameters[1]\r\n\t}\r\n\t// Add `metadata` parameter.\r\n\tparameters.push(metadata)\r\n\t// Call the function.\r\n\treturn _isPossibleNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossible', () => {\r\n\tit('should work', function()\r\n\t{\r\n\t\texpect(isPossibleNumber('+79992223344')).to.equal(true)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', country: 'RU' })).to.equal(true)\r\n\t\texpect(isPossibleNumber({ phone: '111222334', country: 'RU' })).to.equal(false)\r\n\t\texpect(isPossibleNumber({ phone: '11122233445', country: 'RU' })).to.equal(false)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', countryCallingCode: 7 })).to.equal(true)\r\n\t})\r\n\r\n\tit('should work v2', () => {\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '111222334', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '1112223344', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(true)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '11122233445', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\t// Invalid `PhoneNumber` argument.\r\n\t\texpect(() => isPossibleNumber({}, { v2: true })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Empty input is passed.\r\n\t\t// This is just to support `isValidNumber({})`\r\n\t\t// for cases when `parseNumber()` returns `{}`.\r\n\t\texpect(isPossibleNumber({})).to.equal(false)\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344' })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Incorrect country.\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344', country: 'XX' })).to.throw('Unknown country')\r\n\t})\r\n\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000', undefined, metadata)\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\t})\r\n})"],"mappings":";;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,iBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAoD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAAA,SAAAE,QAAAC,CAAA,sCAAAD,OAAA,wBAAAE,MAAA,uBAAAA,MAAA,CAAAC,QAAA,aAAAF,CAAA,kBAAAA,CAAA,gBAAAA,CAAA,WAAAA,CAAA,yBAAAC,MAAA,IAAAD,CAAA,CAAAG,W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AGFF,EAAE,CAAC,oLAAoL,EAAE,YAAM;IAC9L,IAAMQ,WAAW,GAAG,IAAAb,4BAAgB,EAAC,WAAW,EAAED,SAAS,EAAEG,uBAAQ,CAAC;IACtEI,MAAM,CAACO,WAAW,CAACH,OAAO,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC1CF,MAAM,CAACO,WAAW,CAACC,UAAU,CAAC,CAAC,CAAC,CAACP,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CF,MAAM,CAACO,WAAW,CAACE,OAAO,CAAC,CAAC,CAAC,CAACR,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC5CF,MAAM,CAACO,WAAW,CAACD,cAAc,CAAC,CAACL,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EACvD,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"isPossible.test.js","names":["_metadataMin","_interopRequireDefault","require","_isPossible","_parsePhoneNumber","e","__esModule","_typeof","o","Symbol","iterator","constructor","prototype","ownKeys","r","t","Object","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","defineProperty","_toPropertyKey","value","configurable","writable","i","_toPrimitive","toPrimitive","call","TypeError","String","Number","isPossibleNumber","v2","_len","parameters","Array","_key","undefined","parsePhoneNumber","extract","metadata","_isPossibleNumber","describe","it","expect","to","equal","phone","country","countryCallingCode","nationalNumber","phoneNumber","isPossible","isValid"],"sources":["../source/isPossible.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' with { type: 'json' }\r\nimport _isPossibleNumber from './isPossible.js'\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nfunction isPossibleNumber(...parameters) {\r\n\tlet v2\r\n\tif (parameters.length < 1) {\r\n\t\t// `input` parameter.\r\n\t\tparameters.push(undefined)\r\n\t} else {\r\n\t\t// Convert string `input` to a `PhoneNumber` instance.\r\n\t\tif (typeof parameters[0] === 'string') {\r\n\t\t\tv2 = true\r\n\t\t\tparameters[0] = parsePhoneNumber(parameters[0], {\r\n\t\t\t\t...parameters[1],\r\n\t\t\t\textract: false\r\n\t\t\t}, metadata)\r\n\t\t}\r\n\t}\r\n\tif (parameters.length < 2) {\r\n\t\t// `options` parameter.\r\n\t\tparameters.push(undefined)\r\n\t}\r\n\t// Set `v2` flag.\r\n\tparameters[1] = {\r\n\t\tv2,\r\n\t\t...parameters[1]\r\n\t}\r\n\t// Add `metadata` parameter.\r\n\tparameters.push(metadata)\r\n\t// Call the function.\r\n\treturn _isPossibleNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossible', () => {\r\n\tit('should work', function()\r\n\t{\r\n\t\texpect(isPossibleNumber('+79992223344')).to.equal(true)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', country: 'RU' })).to.equal(true)\r\n\t\texpect(isPossibleNumber({ phone: '111222334', country: 'RU' })).to.equal(false)\r\n\t\texpect(isPossibleNumber({ phone: '11122233445', country: 'RU' })).to.equal(false)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', countryCallingCode: 7 })).to.equal(true)\r\n\t})\r\n\r\n\tit('should work v2', () => {\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '111222334', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '1112223344', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(true)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '11122233445', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\t// Invalid `PhoneNumber` argument.\r\n\t\texpect(() => isPossibleNumber({}, { v2: true })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Empty input is passed.\r\n\t\t// This is just to support `isValidNumber({})`\r\n\t\t// for cases when `parseNumber()` returns `{}`.\r\n\t\texpect(isPossibleNumber({})).to.equal(false)\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344' })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Incorrect country.\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344', country: 'XX' })).to.throw('Unknown country')\r\n\t})\r\n\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\t// Tests that Californian numbers `+1310xxxx` are considered possible.\r\n\t\t// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000', undefined, metadata)\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\t})\r\n})"],"mappings":";;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,iBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAoD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAAA,SAAAE,QAAAC,CAAA,sCAAAD,OAAA,wBAAAE,MAAA,uBAAAA,MAAA,CAAAC,QAAA,aAAAF,CAAA,kBAAAA,CAAA,gBAAAA,CAAA,WAAAA,CAAA,yBAAAC,MAAA,IAAAD,CAAA,CAAAG,WAAA,KAAAF,MAAA,IAAAD,CAAA,KAAAC,MAAA,CAAAG,SAAA,qBAAAJ,CAAA,KAAAD,OAAA,CAAAC,CAAA;AAAA,SAAAK,QAAAR,CAAA,EAAAS,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAZ,CAAA,OAAAW,MAAA,CAAAE,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I,CAAC;IAC1CF,MAAM,CAACO,WAAW,CAACC,UAAU,CAAC,CAAC,CAAC,CAACP,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CF,MAAM,CAACO,WAAW,CAACE,OAAO,CAAC,CAAC,CAAC,CAACR,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC5CF,MAAM,CAACO,WAAW,CAACD,cAAc,CAAC,CAACL,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EACvD,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -31,6 +31,8 @@ describe('isPossiblePhoneNumber', function () {
|
|
|
31
31
|
expect((0, _isPossiblePhoneNumber2["default"])('+888 123 456 78901', _metadataMin2["default"])).to.equal(true);
|
|
32
32
|
});
|
|
33
33
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', function () {
|
|
34
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
35
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
34
36
|
expect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true);
|
|
35
37
|
expect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true);
|
|
36
38
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPossiblePhoneNumber.test.js","names":["_isPossiblePhoneNumber2","_interopRequireDefault","require","_metadataMin","_metadataMin2","e","__esModule","isPossiblePhoneNumber","_len","arguments","length","parameters","Array","_key","push","metadata","_isPossiblePhoneNumber","apply","describe","it","expect","to","equal","defaultCountry","oldMetadata"],"sources":["../source/isPossiblePhoneNumber.test.js"],"sourcesContent":["import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\nimport oldMetadata from '../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nfunction isPossiblePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _isPossiblePhoneNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossiblePhoneNumber', () => {\r\n\tit('should detect whether a phone number is possible', () => {\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', 'RU')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' })).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 (800) 555 35 35')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 1 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' +7 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' ')).to.equal(false)\r\n\t})\r\n\r\n\tit('should detect whether a phone number is possible when using old metadata', () => {\r\n\t\texpect(() => _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata)).to.throw('Missing \"possibleLengths\" in metadata.')\r\n\t\texpect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true)\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\texpect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true)\r\n\t})\r\n})"],"mappings":";;AAAA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAwF,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAExF,SAASE,q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AAE,CAACC,KAAK,CAAC,KAAK,CAAC;EACnD,CAAC,CAAC;EAEFH,EAAE,CAAC,0EAA0E,EAAE,YAAM;IACpFC,MAAM,CAAC;MAAA,OAAM,IAAAJ,kCAAsB,EAAC,mBAAmB,EAAE,IAAI,EAAEQ,wBAAW,CAAC;IAAA,EAAC,CAACH,EAAE,SAAM,CAAC,wCAAwC,CAAC;IAC/HD,MAAM,CAAC,IAAAJ,kCAAsB,EAAC,oBAAoB,EAAEQ,wBAAW,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EACjF,CAAC,CAAC;EAEFH,EAAE,CAAC,oLAAoL,EAAE,YAAM;
|
|
1
|
+
{"version":3,"file":"isPossiblePhoneNumber.test.js","names":["_isPossiblePhoneNumber2","_interopRequireDefault","require","_metadataMin","_metadataMin2","e","__esModule","isPossiblePhoneNumber","_len","arguments","length","parameters","Array","_key","push","metadata","_isPossiblePhoneNumber","apply","describe","it","expect","to","equal","defaultCountry","oldMetadata"],"sources":["../source/isPossiblePhoneNumber.test.js"],"sourcesContent":["import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\nimport oldMetadata from '../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nfunction isPossiblePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _isPossiblePhoneNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossiblePhoneNumber', () => {\r\n\tit('should detect whether a phone number is possible', () => {\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', 'RU')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' })).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 (800) 555 35 35')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 1 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' +7 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' ')).to.equal(false)\r\n\t})\r\n\r\n\tit('should detect whether a phone number is possible when using old metadata', () => {\r\n\t\texpect(() => _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata)).to.throw('Missing \"possibleLengths\" in metadata.')\r\n\t\texpect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true)\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\t// Tests that Californian numbers `+1310xxxx` are considered possible.\r\n\t\t// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721\r\n\t\texpect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true)\r\n\t})\r\n})"],"mappings":";;AAAA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAwF,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAExF,SAASE,qBAAqBA,CAAA,EAAgB;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAZC,UAAU,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAVF,UAAU,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAAA;EAC3CF,UAAU,CAACG,IAAI,CAACC,uBAAQ,CAAC;EACzB,OAAOC,kCAA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AoB,EAAEQ,wBAAW,CAAC,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EACjF,CAAC,CAAC;EAEFH,EAAE,CAAC,oLAAoL,EAAE,YAAM;IAC9L;IACA;IACAC,MAAM,CAACb,qBAAqB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAACc,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/DF,MAAM,CAACb,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAACc,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EAC9D,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -78,6 +78,9 @@ describe('parsePhoneNumber', function () {
|
|
|
78
78
|
expect(phoneNumber.nationalNumber).to.equal('123456789');
|
|
79
79
|
});
|
|
80
80
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', function () {
|
|
81
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
82
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
83
|
+
|
|
81
84
|
var phoneNumber = parsePhoneNumber('+13100000');
|
|
82
85
|
expect(phoneNumber.country).to.equal('CA');
|
|
83
86
|
expect(phoneNumber.isPossible()).to.equal(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePhoneNumber.test.js","names":["_parsePhoneNumber2","_interopRequireDefault","require","_metadataMin","e","__esModule","parsePhoneNumber","_len","arguments","length","parameters","Array","_key","push","metadata","_parsePhoneNumber","apply","USE_NON_GEOGRAPHIC_COUNTRY_CODE","describe","it","expect","nationalNumber","to","equal","be","undefined","phoneNumber","number","country","countryCallingCode","defaultCallingCode","isPossible","phoneNumber2","testCorrectness","expectedResult","result","extract","defaultCountry","not","isValid","phoneNumberLocal"],"sources":["../source/parsePhoneNumber.test.js"],"sourcesContent":["import _parsePhoneNumber from './parsePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nfunction parsePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _parsePhoneNumber.apply(this, parameters)\r\n}\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\ndescribe('parsePhoneNumber', () => {\r\n\tit('should parse phone numbers from string', () => {\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('3', 'RU')).to.be.undefined\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\texpect(parsePhoneNumber('')).to.be.undefined\r\n\t})\r\n\r\n\tit('should parse phone numbers when invalid country code is passed', () => {\r\n\t\texpect(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined\r\n\t})\r\n\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('773111632', { defaultCallingCode: '870' })\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should determine the possibility of non-geographic phone numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\tconst phoneNumber2 = parsePhoneNumber('+8707731116321')\r\n\t\texpect(phoneNumber2.isPossible()).to.equal(false)\r\n\t})\r\n\r\n\tit('should support `extract: false` flag', () => {\r\n\t\tconst testCorrectness = (number, expectedResult) => {\r\n\t\t\tconst result = expect(parsePhoneNumber(number, { extract: false, defaultCountry: 'US' }))\r\n\t\t\tif (expectedResult) {\r\n\t\t\t\tresult.to.not.be.undefined\r\n\t\t\t} else {\r\n\t\t\t\tresult.to.be.undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\ttestCorrectness('Call: (213) 373-4253', false)\r\n\t\ttestCorrectness('(213) 373-4253x', false)\r\n\t\ttestCorrectness('(213) 373-4253', true)\r\n\t\ttestCorrectness('- (213) 373-4253 -', true)\r\n\t\ttestCorrectness('+1 (213) 373-4253', true)\r\n\t\ttestCorrectness(' +1 (213) 373-4253', false)\r\n\t})\r\n\r\n\tit('should not prematurely strip a possible national prefix from Chinese numbers', () => {\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57\r\n\t\tconst phoneNumber = parsePhoneNumber('+86123456789')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(false)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('123456789')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000')\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\r\n\t\tconst phoneNumberLocal = parsePhoneNumber('3100000', 'CA')\r\n\t\texpect(phoneNumberLocal.country).to.equal('CA')\r\n\t\texpect(phoneNumberLocal.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.isValid()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.nationalNumber).to.equal('3100000')\r\n\t})\r\n})\r\n"],"mappings":";;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAiE,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAEjE,SAASE,gBAAgBA,CAAA,EAAgB;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAZC,UAAU,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAVF,UAAU,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAAA;EACtCF,UAAU,CAACG,IAAI,CAACC,uBAAQ,CAAC;EACzB,OAAOC,6BAAiB,CAACC,KAAK,CAAC,IAAI,EAAEN,UAAU,CAAC;AACjD;AAEA,IAAMO,+BAA+B,GAAG,KAAK;AAE7CC,QAAQ,CAAC,kBAAkB,EAAE,YAAM;EAClCC,EAAE,CAAC,wCAAwC,EAAE,YAAM;IAClDC,MAAM,CAACd,gBAAgB,CAAC,2BAA2B,EAAE,IAAI,CAAC,CAACe,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,YAAY,CAAC;IACjGH,MAAM,CAACd,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAACgB,EAAE,CAACE,EAAE,CAACC,SAAS;EACpD,CAAC,CAAC;EAEFN,EAAE,CAAC,2BAA2B,EAAE,YAAM;IACrCC,MAAM,CAACd,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAACgB,EAAE,CAACE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MAAM,CAACoB,gBAAgB,CAACnB,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EAC5D,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"parsePhoneNumber.test.js","names":["_parsePhoneNumber2","_interopRequireDefault","require","_metadataMin","e","__esModule","parsePhoneNumber","_len","arguments","length","parameters","Array","_key","push","metadata","_parsePhoneNumber","apply","USE_NON_GEOGRAPHIC_COUNTRY_CODE","describe","it","expect","nationalNumber","to","equal","be","undefined","phoneNumber","number","country","countryCallingCode","defaultCallingCode","isPossible","phoneNumber2","testCorrectness","expectedResult","result","extract","defaultCountry","not","isValid","phoneNumberLocal"],"sources":["../source/parsePhoneNumber.test.js"],"sourcesContent":["import _parsePhoneNumber from './parsePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nfunction parsePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _parsePhoneNumber.apply(this, parameters)\r\n}\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\ndescribe('parsePhoneNumber', () => {\r\n\tit('should parse phone numbers from string', () => {\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('3', 'RU')).to.be.undefined\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\texpect(parsePhoneNumber('')).to.be.undefined\r\n\t})\r\n\r\n\tit('should parse phone numbers when invalid country code is passed', () => {\r\n\t\texpect(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined\r\n\t})\r\n\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('773111632', { defaultCallingCode: '870' })\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should determine the possibility of non-geographic phone numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\tconst phoneNumber2 = parsePhoneNumber('+8707731116321')\r\n\t\texpect(phoneNumber2.isPossible()).to.equal(false)\r\n\t})\r\n\r\n\tit('should support `extract: false` flag', () => {\r\n\t\tconst testCorrectness = (number, expectedResult) => {\r\n\t\t\tconst result = expect(parsePhoneNumber(number, { extract: false, defaultCountry: 'US' }))\r\n\t\t\tif (expectedResult) {\r\n\t\t\t\tresult.to.not.be.undefined\r\n\t\t\t} else {\r\n\t\t\t\tresult.to.be.undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\ttestCorrectness('Call: (213) 373-4253', false)\r\n\t\ttestCorrectness('(213) 373-4253x', false)\r\n\t\ttestCorrectness('(213) 373-4253', true)\r\n\t\ttestCorrectness('- (213) 373-4253 -', true)\r\n\t\ttestCorrectness('+1 (213) 373-4253', true)\r\n\t\ttestCorrectness(' +1 (213) 373-4253', false)\r\n\t})\r\n\r\n\tit('should not prematurely strip a possible national prefix from Chinese numbers', () => {\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57\r\n\t\tconst phoneNumber = parsePhoneNumber('+86123456789')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(false)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('123456789')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\t// Tests that Californian numbers `+1310xxxx` are considered possible.\r\n\t\t// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721\r\n\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000')\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\r\n\t\tconst phoneNumberLocal = parsePhoneNumber('3100000', 'CA')\r\n\t\texpect(phoneNumberLocal.country).to.equal('CA')\r\n\t\texpect(phoneNumberLocal.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.isValid()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.nationalNumber).to.equal('3100000')\r\n\t})\r\n})\r\n"],"mappings":";;AAAA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAiE,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAEjE,SAASE,gBAAgBA,CAAA,EAAgB;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAZC,UAAU,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAVF,UAAU,CAAA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,CAACK,UAAU,CAAC,CAAC,CAAC,CAACT,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CH,MAAM,CAACM,WAAW,CAACa,OAAO,CAAC,CAAC,CAAC,CAACjB,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC5CH,MAAM,CAACM,WAAW,CAACL,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;IAEtD,IAAMiB,gBAAgB,GAAGlC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC;IAC1Dc,MAAM,CAACoB,gBAAgB,CAACZ,OAAO,CAAC,CAACN,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CH,MAAM,CAACoB,gBAAgB,CAACT,UAAU,CAAC,CAAC,CAAC,CAACT,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACpDH,MAAM,CAACoB,gBAAgB,CAACD,OAAO,CAAC,CAAC,CAAC,CAACjB,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACjDH,MAAM,CAACoB,gBAAgB,CAACnB,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EAC5D,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Pulls the latest metadata from Google's repo, and, if it has changed,
|
|
2
2
|
// pushes the changes in the main branch and releases a new version on `npm`.
|
|
3
3
|
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import gmailSend from 'gmail-send'
|
|
6
|
+
|
|
4
7
|
import update_metadata_from_google_metadata from './helpers/update-metadata-from-google-metadata.js'
|
|
5
8
|
import commit from './helpers/commit.js'
|
|
6
9
|
import exec from './helpers/exec.js'
|
|
@@ -14,7 +17,7 @@ if (update_metadata_from_google_metadata(googleMetadataFilePath, metadataInfoFil
|
|
|
14
17
|
|
|
15
18
|
console.log()
|
|
16
19
|
console.log('========================================')
|
|
17
|
-
console.log('=
|
|
20
|
+
console.log('= Push the changes to the repository =')
|
|
18
21
|
console.log('========================================')
|
|
19
22
|
console.log()
|
|
20
23
|
|
|
@@ -22,21 +25,68 @@ if (update_metadata_from_google_metadata(googleMetadataFilePath, metadataInfoFil
|
|
|
22
25
|
|
|
23
26
|
console.log()
|
|
24
27
|
console.log('========================================')
|
|
25
|
-
console.log('=
|
|
28
|
+
console.log('= Increment the version =')
|
|
26
29
|
console.log('========================================')
|
|
27
30
|
console.log()
|
|
28
31
|
|
|
29
32
|
console.log(exec('npm version patch'))
|
|
30
33
|
console.log(exec('git push'))
|
|
31
34
|
|
|
32
|
-
// `npm` requires "two-factor authentication", so programmatic `npm publish`
|
|
33
|
-
// won't work without human intervention.
|
|
34
|
-
console.log(exec('npm publish'))
|
|
35
|
-
console.log(exec('git push'))
|
|
36
|
-
|
|
37
35
|
console.log()
|
|
38
36
|
console.log('========================================')
|
|
39
|
-
console.log('=
|
|
37
|
+
console.log('= Publish the new version =')
|
|
40
38
|
console.log('========================================')
|
|
41
39
|
console.log()
|
|
40
|
+
|
|
41
|
+
// `npm` requires "two-factor authentication", so running an `npm publish`
|
|
42
|
+
// command programmatically won't work without human intervention.
|
|
43
|
+
//
|
|
44
|
+
// To work around that, one could optionally specify GMail credentials.
|
|
45
|
+
// In that case, instead of attempting to run `npm publish` command,
|
|
46
|
+
// it will send an email notification to do that manually.
|
|
47
|
+
//
|
|
48
|
+
const emailSettings = getEmailSettings()
|
|
49
|
+
if (emailSettings) {
|
|
50
|
+
// Send an email notification about manually publishing the new version of the package to `npm`.
|
|
51
|
+
gmailSend({
|
|
52
|
+
user: emailSettings.email,
|
|
53
|
+
pass: emailSettings.accessToken,
|
|
54
|
+
to: emailSettings.email,
|
|
55
|
+
subject: '[libphonenumber-js] Publish a new version',
|
|
56
|
+
text: 'A new version of `libphonenumber-js` has been pushed to the repository and should be published manually to `npm` — run `npm publish` in `libphonenumber-js` directory.',
|
|
57
|
+
// html: '<b>html text</b>' // alternative to specifying `text`, one could specify `html`.
|
|
58
|
+
})()
|
|
59
|
+
|
|
60
|
+
console.log()
|
|
61
|
+
console.log('==========================================================')
|
|
62
|
+
console.log('= Email notification sent. Publish the package manually. =')
|
|
63
|
+
console.log('==========================================================')
|
|
64
|
+
console.log()
|
|
65
|
+
} else {
|
|
66
|
+
console.log(exec('npm publish'))
|
|
67
|
+
|
|
68
|
+
console.log()
|
|
69
|
+
console.log('========================================')
|
|
70
|
+
console.log('= Published =')
|
|
71
|
+
console.log('========================================')
|
|
72
|
+
console.log()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Reads email settings from a JSON file just outside of `libphonenumber-js` repo folder.
|
|
77
|
+
function getEmailSettings() {
|
|
78
|
+
const emailSettingsPath = '../libphonenumber-js-autoupdate-email-notification-settings.json'
|
|
79
|
+
if (fs.existsSync(emailSettingsPath)) {
|
|
80
|
+
const emailSettings = JSON.parse(fs.readFileSync(emailSettingsPath, 'utf-8'))
|
|
81
|
+
// Validate `emailSettings`.
|
|
82
|
+
if (!emailSettings.email) {
|
|
83
|
+
throw new Error('`email` parameter not specified in the email config file')
|
|
84
|
+
}
|
|
85
|
+
// The instructions on how to obtain an `accessToken` are described in `gmail-send` readme:
|
|
86
|
+
// https://www.npmjs.com/package/gmail-send
|
|
87
|
+
if (!emailSettings.accessToken) {
|
|
88
|
+
throw new Error('`accessToken` parameter not specified in the email config file')
|
|
89
|
+
}
|
|
90
|
+
return emailSettings;
|
|
91
|
+
}
|
|
42
92
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import getUncommittedChanges from './helpers/getUncommittedChanges.js';
|
|
2
|
+
|
|
3
|
+
getUncommittedChanges().then((uncommittedChanges) => {
|
|
4
|
+
if (uncommittedChanges.length > 0) {
|
|
5
|
+
console.error(new Error(`You have uncommitted files in your repository:\n${uncommittedChanges.map(({ filename }) => filename).join('\n')}`))
|
|
6
|
+
process.exit(1)
|
|
7
|
+
}
|
|
8
|
+
}).catch((error) => {
|
|
9
|
+
console.error(error)
|
|
10
|
+
process.exit(1)
|
|
11
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { exec } from 'child_process'
|
|
2
|
+
|
|
3
|
+
export default function getUncommittedChanges() {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
exec('git status --porcelain', (error, stdout, stderr) => {
|
|
6
|
+
if (error) {
|
|
7
|
+
reject(error);
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (stderr) {
|
|
12
|
+
reject(new Error(stderr.toString()))
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const output = stdout.toString().trim()
|
|
17
|
+
|
|
18
|
+
if (!output) {
|
|
19
|
+
resolve([]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const uncommittedFiles = output.trim().split('\n').map((line) => {
|
|
23
|
+
line = line.trim()
|
|
24
|
+
const status = line[0]
|
|
25
|
+
line = line.slice(2)
|
|
26
|
+
const filename = line
|
|
27
|
+
return { status, filename }
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
resolve(uncommittedFiles)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
}
|
|
@@ -7,7 +7,7 @@ import exec from './exec.js'
|
|
|
7
7
|
// generates JSON metadata files from it, runs the tests and updates `CHANGELOG.md`.
|
|
8
8
|
export default function(googleMetadataFilePath, metadataInfoFilePath)
|
|
9
9
|
{
|
|
10
|
-
let metadata_changed = exec(`git ls-files --modified ${googleMetadataFilePath}`)
|
|
10
|
+
let metadata_changed = true || exec(`git ls-files --modified ${googleMetadataFilePath}`)
|
|
11
11
|
|
|
12
12
|
if (!metadata_changed)
|
|
13
13
|
{
|
package/es6/isPossible.test.js
CHANGED
|
@@ -104,6 +104,8 @@ describe('isPossible', function () {
|
|
|
104
104
|
}).to["throw"]('Unknown country');
|
|
105
105
|
});
|
|
106
106
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', function () {
|
|
107
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
108
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
107
109
|
var phoneNumber = parsePhoneNumber('+13100000', undefined, metadata);
|
|
108
110
|
expect(phoneNumber.country).to.equal('CA');
|
|
109
111
|
expect(phoneNumber.isPossible()).to.equal(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPossible.test.js","names":["metadata","type","_isPossibleNumber","parsePhoneNumber","isPossibleNumber","v2","_len","arguments","length","parameters","Array","_key","push","undefined","_objectSpread","extract","apply","describe","it","expect","to","equal","phone","country","countryCallingCode","nationalNumber","phoneNumber","isPossible","isValid"],"sources":["../source/isPossible.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' with { type: 'json' }\r\nimport _isPossibleNumber from './isPossible.js'\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nfunction isPossibleNumber(...parameters) {\r\n\tlet v2\r\n\tif (parameters.length < 1) {\r\n\t\t// `input` parameter.\r\n\t\tparameters.push(undefined)\r\n\t} else {\r\n\t\t// Convert string `input` to a `PhoneNumber` instance.\r\n\t\tif (typeof parameters[0] === 'string') {\r\n\t\t\tv2 = true\r\n\t\t\tparameters[0] = parsePhoneNumber(parameters[0], {\r\n\t\t\t\t...parameters[1],\r\n\t\t\t\textract: false\r\n\t\t\t}, metadata)\r\n\t\t}\r\n\t}\r\n\tif (parameters.length < 2) {\r\n\t\t// `options` parameter.\r\n\t\tparameters.push(undefined)\r\n\t}\r\n\t// Set `v2` flag.\r\n\tparameters[1] = {\r\n\t\tv2,\r\n\t\t...parameters[1]\r\n\t}\r\n\t// Add `metadata` parameter.\r\n\tparameters.push(metadata)\r\n\t// Call the function.\r\n\treturn _isPossibleNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossible', () => {\r\n\tit('should work', function()\r\n\t{\r\n\t\texpect(isPossibleNumber('+79992223344')).to.equal(true)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', country: 'RU' })).to.equal(true)\r\n\t\texpect(isPossibleNumber({ phone: '111222334', country: 'RU' })).to.equal(false)\r\n\t\texpect(isPossibleNumber({ phone: '11122233445', country: 'RU' })).to.equal(false)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', countryCallingCode: 7 })).to.equal(true)\r\n\t})\r\n\r\n\tit('should work v2', () => {\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '111222334', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '1112223344', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(true)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '11122233445', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\t// Invalid `PhoneNumber` argument.\r\n\t\texpect(() => isPossibleNumber({}, { v2: true })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Empty input is passed.\r\n\t\t// This is just to support `isValidNumber({})`\r\n\t\t// for cases when `parseNumber()` returns `{}`.\r\n\t\texpect(isPossibleNumber({})).to.equal(false)\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344' })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Incorrect country.\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344', country: 'XX' })).to.throw('Unknown country')\r\n\t})\r\n\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000', undefined, metadata)\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\t})\r\n})"],"mappings":";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C,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"isPossible.test.js","names":["metadata","type","_isPossibleNumber","parsePhoneNumber","isPossibleNumber","v2","_len","arguments","length","parameters","Array","_key","push","undefined","_objectSpread","extract","apply","describe","it","expect","to","equal","phone","country","countryCallingCode","nationalNumber","phoneNumber","isPossible","isValid"],"sources":["../source/isPossible.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' with { type: 'json' }\r\nimport _isPossibleNumber from './isPossible.js'\r\nimport parsePhoneNumber from './parsePhoneNumber.js'\r\n\r\nfunction isPossibleNumber(...parameters) {\r\n\tlet v2\r\n\tif (parameters.length < 1) {\r\n\t\t// `input` parameter.\r\n\t\tparameters.push(undefined)\r\n\t} else {\r\n\t\t// Convert string `input` to a `PhoneNumber` instance.\r\n\t\tif (typeof parameters[0] === 'string') {\r\n\t\t\tv2 = true\r\n\t\t\tparameters[0] = parsePhoneNumber(parameters[0], {\r\n\t\t\t\t...parameters[1],\r\n\t\t\t\textract: false\r\n\t\t\t}, metadata)\r\n\t\t}\r\n\t}\r\n\tif (parameters.length < 2) {\r\n\t\t// `options` parameter.\r\n\t\tparameters.push(undefined)\r\n\t}\r\n\t// Set `v2` flag.\r\n\tparameters[1] = {\r\n\t\tv2,\r\n\t\t...parameters[1]\r\n\t}\r\n\t// Add `metadata` parameter.\r\n\tparameters.push(metadata)\r\n\t// Call the function.\r\n\treturn _isPossibleNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossible', () => {\r\n\tit('should work', function()\r\n\t{\r\n\t\texpect(isPossibleNumber('+79992223344')).to.equal(true)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', country: 'RU' })).to.equal(true)\r\n\t\texpect(isPossibleNumber({ phone: '111222334', country: 'RU' })).to.equal(false)\r\n\t\texpect(isPossibleNumber({ phone: '11122233445', country: 'RU' })).to.equal(false)\r\n\r\n\t\texpect(isPossibleNumber({ phone: '1112223344', countryCallingCode: 7 })).to.equal(true)\r\n\t})\r\n\r\n\tit('should work v2', () => {\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '111222334', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '1112223344', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(true)\r\n\t\texpect(\r\n isPossibleNumber({ nationalNumber: '11122233445', countryCallingCode: 7 }, { v2: true })\r\n ).to.equal(false)\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\t// Invalid `PhoneNumber` argument.\r\n\t\texpect(() => isPossibleNumber({}, { v2: true })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Empty input is passed.\r\n\t\t// This is just to support `isValidNumber({})`\r\n\t\t// for cases when `parseNumber()` returns `{}`.\r\n\t\texpect(isPossibleNumber({})).to.equal(false)\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344' })).to.throw('Invalid phone number object passed')\r\n\r\n\t\t// Incorrect country.\r\n\t\texpect(() => isPossibleNumber({ phone: '1112223344', country: 'XX' })).to.throw('Unknown country')\r\n\t})\r\n\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\t// Tests that Californian numbers `+1310xxxx` are considered possible.\r\n\t\t// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000', undefined, metadata)\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\t})\r\n})"],"mappings":";;;;;;AAAA,OAAOA,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAC/D,OAAOC,iBAAiB,MAAM,iBAAiB;AAC/C,OAAOC,gBAAgB,MAAM,uBAAuB;AAEpD,SAASC,gB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,CAAC,CAAC,CAAC,EAAE;QAAEC,EAAE,EAAE;MAAK,CAAC,CAAC;IAAA,EAAC,CAACe,EAAE,SAAM,CAAC,oCAAoC,CAAC;;IAE/F;IACA;IACA;IACAD,MAAM,CAACf,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAACgB,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IAC5CF,MAAM,CAAC;MAAA,OAAMf,gBAAgB,CAAC;QAAEkB,KAAK,EAAE;MAAa,CAAC,CAAC;IAAA,EAAC,CAACF,EAAE,SAAM,CAAC,oCAAoC,CAAC;;IAEtG;IACAD,MAAM,CAAC;MAAA,OAAMf,gBAAgB,CAAC;QAAEkB,KAAK,EAAE,YAAY;QAAEC,OAAO,EAAE;MAAK,CAAC,CAAC;IAAA,EAAC,CAACH,EAAE,SAAM,CAAC,iBAAiB,CAAC;EACnG,CAAC,CAAC;EAGFF,EAAE,CAAC,oLAAoL,EAAE,YAAM;IAC9L;IACA;IACA,IAAMQ,WAAW,GAAGvB,gBAAgB,CAAC,WAAW,EAAEU,SAAS,EAAEb,QAAQ,CAAC;IACtEmB,MAAM,CAACO,WAAW,CAACH,OAAO,CAAC,CAACH,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC1CF,MAAM,CAACO,WAAW,CAACC,UAAU,CAAC,CAAC,CAAC,CAACP,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CF,MAAM,CAACO,WAAW,CAACE,OAAO,CAAC,CAAC,CAAC,CAACR,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC5CF,MAAM,CAACO,WAAW,CAACD,cAAc,CAAC,CAACL,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EACvD,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -28,6 +28,8 @@ describe('isPossiblePhoneNumber', function () {
|
|
|
28
28
|
expect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true);
|
|
29
29
|
});
|
|
30
30
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', function () {
|
|
31
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
32
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
31
33
|
expect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true);
|
|
32
34
|
expect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true);
|
|
33
35
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPossiblePhoneNumber.test.js","names":["_isPossiblePhoneNumber","metadata","type","oldMetadata","isPossiblePhoneNumber","_len","arguments","length","parameters","Array","_key","push","apply","describe","it","expect","to","equal","defaultCountry"],"sources":["../source/isPossiblePhoneNumber.test.js"],"sourcesContent":["import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\nimport oldMetadata from '../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nfunction isPossiblePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _isPossiblePhoneNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossiblePhoneNumber', () => {\r\n\tit('should detect whether a phone number is possible', () => {\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', 'RU')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' })).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 (800) 555 35 35')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 1 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' +7 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' ')).to.equal(false)\r\n\t})\r\n\r\n\tit('should detect whether a phone number is possible when using old metadata', () => {\r\n\t\texpect(() => _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata)).to.throw('Missing \"possibleLengths\" in metadata.')\r\n\t\texpect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true)\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\texpect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true)\r\n\t})\r\n})"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,4BAA4B;AAC/D,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAC/D,OAAOC,WAAW,MAAM,0CAA0C,QAAQD,IAAI,EAAE,MAAM;AAEtF,SAASE,qBAAqBA,CAAA,EAAgB;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAZC,UAAU,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAVF,UAAU,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAAA;EAC3CF,UAAU,CAACG,IAAI,CAACV,QAAQ,CAAC;EACzB,OAAOD,sBAAsB,CAACY,KAAK,CAAC,IAAI,EAAEJ,UAAU,CAAC;AACtD;AAEAK,QAAQ,CAAC,uBAAuB,EAAE,YAAM;EACvCC,EAAE,CAAC,kDAAkD,EAAE,YAAM;IAC5DC,MAAM,CAACX,qBAAqB,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACvEF,MAAM,CAACX,qBAAqB,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IAC1EF,MAAM,CAACX,qBAAqB,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IAC9EF,MAAM,CAACX,qBAAqB,CAAC,mBAAmB,EAAE;MAAEc,cAAc,EAAE;IAAK,CAAC,CAAC,CAAC,CAACF,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC3FF,MAAM,CAACX,qBAAqB,CAAC,oBAAoB,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAClEF,MAAM,CAACX,qBAAqB,CAAC,sBAAsB,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IACrEF,MAAM,CAACX,qBAAqB,CAAC,qBAAqB,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IACpEF,MAAM,CAACX,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;EACnD,CAAC,CAAC;EAEFH,EAAE,CAAC,0EAA0E,EAAE,YAAM;IACpFC,MAAM,CAAC;MAAA,OAAMf,sBAAsB,CAAC,mBAAmB,EAAE,IAAI,EAAEG,WAAW,CAAC;IAAA,EAAC,CAACa,EAAE,SAAM,CAAC,wCAAwC,CAAC;IAC/HD,MAAM,CAACf,sBAAsB,CAAC,oBAAoB,EAAEG,WAAW,CAAC,CAAC,CAACa,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EACjF,CAAC,CAAC;EAEFH,EAAE,CAAC,oLAAoL,EAAE,YAAM;
|
|
1
|
+
{"version":3,"file":"isPossiblePhoneNumber.test.js","names":["_isPossiblePhoneNumber","metadata","type","oldMetadata","isPossiblePhoneNumber","_len","arguments","length","parameters","Array","_key","push","apply","describe","it","expect","to","equal","defaultCountry"],"sources":["../source/isPossiblePhoneNumber.test.js"],"sourcesContent":["import _isPossiblePhoneNumber from './isPossiblePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\nimport oldMetadata from '../test/metadata/1.0.0/metadata.min.json' with { type: 'json' }\r\n\r\nfunction isPossiblePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _isPossiblePhoneNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isPossiblePhoneNumber', () => {\r\n\tit('should detect whether a phone number is possible', () => {\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', 'RU')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' })).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 (800) 555 35 35')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('+7 1 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' +7 (800) 555 35 35')).to.equal(false)\r\n\t\texpect(isPossiblePhoneNumber(' ')).to.equal(false)\r\n\t})\r\n\r\n\tit('should detect whether a phone number is possible when using old metadata', () => {\r\n\t\texpect(() => _isPossiblePhoneNumber('8 (800) 555 35 35', 'RU', oldMetadata)).to.throw('Missing \"possibleLengths\" in metadata.')\r\n\t\texpect(_isPossiblePhoneNumber('+888 123 456 78901', oldMetadata)).to.equal(true)\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\t// Tests that Californian numbers `+1310xxxx` are considered possible.\r\n\t\t// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721\r\n\t\texpect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true)\r\n\t\texpect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true)\r\n\t})\r\n})"],"mapp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,CAAC,KAAK,CAAC;IACrEF,MAAM,CAACX,qBAAqB,CAAC,qBAAqB,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;IACpEF,MAAM,CAACX,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,KAAK,CAAC;EACnD,CAAC,CAAC;EAEFH,EAAE,CAAC,0EAA0E,EAAE,YAAM;IACpFC,MAAM,CAAC;MAAA,OAAMf,sBAAsB,CAAC,mBAAmB,EAAE,IAAI,EAAEG,WAAW,CAAC;IAAA,EAAC,CAACa,EAAE,SAAM,CAAC,wCAAwC,CAAC;IAC/HD,MAAM,CAACf,sBAAsB,CAAC,oBAAoB,EAAEG,WAAW,CAAC,CAAC,CAACa,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EACjF,CAAC,CAAC;EAEFH,EAAE,CAAC,oLAAoL,EAAE,YAAM;IAC9L;IACA;IACAC,MAAM,CAACX,qBAAqB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/DF,MAAM,CAACX,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAACY,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EAC9D,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
@@ -75,6 +75,9 @@ describe('parsePhoneNumber', function () {
|
|
|
75
75
|
expect(phoneNumber.nationalNumber).to.equal('123456789');
|
|
76
76
|
});
|
|
77
77
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', function () {
|
|
78
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
79
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
80
|
+
|
|
78
81
|
var phoneNumber = parsePhoneNumber('+13100000');
|
|
79
82
|
expect(phoneNumber.country).to.equal('CA');
|
|
80
83
|
expect(phoneNumber.isPossible()).to.equal(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePhoneNumber.test.js","names":["_parsePhoneNumber","metadata","type","parsePhoneNumber","_len","arguments","length","parameters","Array","_key","push","apply","USE_NON_GEOGRAPHIC_COUNTRY_CODE","describe","it","expect","nationalNumber","to","equal","be","undefined","phoneNumber","number","country","countryCallingCode","defaultCallingCode","isPossible","phoneNumber2","testCorrectness","expectedResult","result","extract","defaultCountry","not","isValid","phoneNumberLocal"],"sources":["../source/parsePhoneNumber.test.js"],"sourcesContent":["import _parsePhoneNumber from './parsePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nfunction parsePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _parsePhoneNumber.apply(this, parameters)\r\n}\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\ndescribe('parsePhoneNumber', () => {\r\n\tit('should parse phone numbers from string', () => {\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('3', 'RU')).to.be.undefined\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\texpect(parsePhoneNumber('')).to.be.undefined\r\n\t})\r\n\r\n\tit('should parse phone numbers when invalid country code is passed', () => {\r\n\t\texpect(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined\r\n\t})\r\n\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('773111632', { defaultCallingCode: '870' })\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should determine the possibility of non-geographic phone numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\tconst phoneNumber2 = parsePhoneNumber('+8707731116321')\r\n\t\texpect(phoneNumber2.isPossible()).to.equal(false)\r\n\t})\r\n\r\n\tit('should support `extract: false` flag', () => {\r\n\t\tconst testCorrectness = (number, expectedResult) => {\r\n\t\t\tconst result = expect(parsePhoneNumber(number, { extract: false, defaultCountry: 'US' }))\r\n\t\t\tif (expectedResult) {\r\n\t\t\t\tresult.to.not.be.undefined\r\n\t\t\t} else {\r\n\t\t\t\tresult.to.be.undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\ttestCorrectness('Call: (213) 373-4253', false)\r\n\t\ttestCorrectness('(213) 373-4253x', false)\r\n\t\ttestCorrectness('(213) 373-4253', true)\r\n\t\ttestCorrectness('- (213) 373-4253 -', true)\r\n\t\ttestCorrectness('+1 (213) 373-4253', true)\r\n\t\ttestCorrectness(' +1 (213) 373-4253', false)\r\n\t})\r\n\r\n\tit('should not prematurely strip a possible national prefix from Chinese numbers', () => {\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57\r\n\t\tconst phoneNumber = parsePhoneNumber('+86123456789')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(false)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('123456789')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000')\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\r\n\t\tconst phoneNumberLocal = parsePhoneNumber('3100000', 'CA')\r\n\t\texpect(phoneNumberLocal.country).to.equal('CA')\r\n\t\texpect(phoneNumberLocal.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.isValid()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.nationalNumber).to.equal('3100000')\r\n\t})\r\n})\r\n"],"mappings":"AAAA,OAAOA,iBAAiB,MAAM,uBAAuB;AACrD,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAE/D,SAASC,gBAAgBA,CAAA,EAAgB;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAZC,UAAU,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAVF,UAAU,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAAA;EACtCF,UAAU,CAACG,IAAI,CAACT,QAAQ,CAAC;EACzB,OAAOD,iBAAiB,CAACW,KAAK,CAAC,IAAI,EAAEJ,UAAU,CAAC;AACjD;AAEA,IAAMK,+BAA+B,GAAG,KAAK;AAE7CC,QAAQ,CAAC,kBAAkB,EAAE,YAAM;EAClCC,EAAE,CAAC,wCAAwC,EAAE,YAAM;IAClDC,MAAM,CAACZ,gBAAgB,CAAC,2BAA2B,EAA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;IAC1DY,MAAM,CAACoB,gBAAgB,CAACZ,OAAO,CAAC,CAACN,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CH,MAAM,CAACoB,gBAAgB,CAACT,UAAU,CAAC,CAAC,CAAC,CAACT,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACpDH,MAAM,CAACoB,gBAAgB,CAACD,OAAO,CAAC,CAAC,CAAC,CAACjB,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACjDH,MAAM,CAACoB,gBAAgB,CAACnB,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EAC5D,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"parsePhoneNumber.test.js","names":["_parsePhoneNumber","metadata","type","parsePhoneNumber","_len","arguments","length","parameters","Array","_key","push","apply","USE_NON_GEOGRAPHIC_COUNTRY_CODE","describe","it","expect","nationalNumber","to","equal","be","undefined","phoneNumber","number","country","countryCallingCode","defaultCallingCode","isPossible","phoneNumber2","testCorrectness","expectedResult","result","extract","defaultCountry","not","isValid","phoneNumberLocal"],"sources":["../source/parsePhoneNumber.test.js"],"sourcesContent":["import _parsePhoneNumber from './parsePhoneNumber.js'\r\nimport metadata from '../metadata.min.json' with { type: 'json' }\r\n\r\nfunction parsePhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _parsePhoneNumber.apply(this, parameters)\r\n}\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\ndescribe('parsePhoneNumber', () => {\r\n\tit('should parse phone numbers from string', () => {\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('3', 'RU')).to.be.undefined\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\texpect(parsePhoneNumber('')).to.be.undefined\r\n\t})\r\n\r\n\tit('should parse phone numbers when invalid country code is passed', () => {\r\n\t\texpect(parsePhoneNumber('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber).to.equal('8005553535')\r\n\t\texpect(parsePhoneNumber('Phone: 8 (800) 555-35-35.', 'XX')).to.be.undefined\r\n\t})\r\n\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should parse non-geographic numbering plan phone numbers (default country code) (extended)', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('773111632', { defaultCallingCode: '870' })\r\n\t\texpect(phoneNumber.number).to.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\texpect(phoneNumber.country).to.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\texpect(phoneNumber.countryCallingCode).to.equal('870')\r\n\t})\r\n\r\n\tit('should determine the possibility of non-geographic phone numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumber('+870773111632')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\tconst phoneNumber2 = parsePhoneNumber('+8707731116321')\r\n\t\texpect(phoneNumber2.isPossible()).to.equal(false)\r\n\t})\r\n\r\n\tit('should support `extract: false` flag', () => {\r\n\t\tconst testCorrectness = (number, expectedResult) => {\r\n\t\t\tconst result = expect(parsePhoneNumber(number, { extract: false, defaultCountry: 'US' }))\r\n\t\t\tif (expectedResult) {\r\n\t\t\t\tresult.to.not.be.undefined\r\n\t\t\t} else {\r\n\t\t\t\tresult.to.be.undefined\r\n\t\t\t}\r\n\t\t}\r\n\t\ttestCorrectness('Call: (213) 373-4253', false)\r\n\t\ttestCorrectness('(213) 373-4253x', false)\r\n\t\ttestCorrectness('(213) 373-4253', true)\r\n\t\ttestCorrectness('- (213) 373-4253 -', true)\r\n\t\ttestCorrectness('+1 (213) 373-4253', true)\r\n\t\ttestCorrectness(' +1 (213) 373-4253', false)\r\n\t})\r\n\r\n\tit('should not prematurely strip a possible national prefix from Chinese numbers', () => {\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/57\r\n\t\tconst phoneNumber = parsePhoneNumber('+86123456789')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(false)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('123456789')\r\n\t})\r\n\r\n\tit('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-\"main\" country and is not possible in the \"main\" country', () => {\r\n\t\t// Tests that Californian numbers `+1310xxxx` are considered possible.\r\n\t\t// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721\r\n\r\n\t\tconst phoneNumber = parsePhoneNumber('+13100000')\r\n\t\texpect(phoneNumber.country).to.equal('CA')\r\n\t\texpect(phoneNumber.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumber.isValid()).to.equal(true)\r\n\t\texpect(phoneNumber.nationalNumber).to.equal('3100000')\r\n\r\n\t\tconst phoneNumberLocal = parsePhoneNumber('3100000', 'CA')\r\n\t\texpect(phoneNumberLocal.country).to.equal('CA')\r\n\t\texpect(phoneNumberLocal.isPossible()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.isValid()).to.equal(true)\r\n\t\texpect(phoneNumberLocal.nationalNumber).to.equal('3100000')\r\n\t})\r\n})\r\n"],"mappings":"AAAA,OAAOA,iBAAiB,MAAM,uBAAuB;AACrD,OAAOC,QAAQ,MAAM,sBAAsB,QAAQC,IAAI,EAAE,MAAM;AAE/D,SAASC,gBAAgBA,CAAA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ACA;;IAEA,IAAMO,WAAW,GAAGlB,gBAAgB,CAAC,WAAW,CAAC;IACjDY,MAAM,CAACM,WAAW,CAACE,OAAO,CAAC,CAACN,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC1CH,MAAM,CAACM,WAAW,CAACK,UAAU,CAAC,CAAC,CAAC,CAACT,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CH,MAAM,CAACM,WAAW,CAACa,OAAO,CAAC,CAAC,CAAC,CAACjB,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC5CH,MAAM,CAACM,WAAW,CAACL,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;IAEtD,IAAMiB,gBAAgB,GAAGhC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC;IAC1DY,MAAM,CAACoB,gBAAgB,CAACZ,OAAO,CAAC,CAACN,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IAC/CH,MAAM,CAACoB,gBAAgB,CAACT,UAAU,CAAC,CAAC,CAAC,CAACT,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACpDH,MAAM,CAACoB,gBAAgB,CAACD,OAAO,CAAC,CAAC,CAAC,CAACjB,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;IACjDH,MAAM,CAACoB,gBAAgB,CAACnB,cAAc,CAAC,CAACC,EAAE,CAACC,KAAK,CAAC,SAAS,CAAC;EAC5D,CAAC,CAAC;AACH,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libphonenumber-js",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.21",
|
|
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",
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"cpy-cli": "^5.0.0",
|
|
100
100
|
"crlf": "^1.1.1",
|
|
101
101
|
"cross-env": "^10.0.0",
|
|
102
|
+
"gmail-send": "^1.8.14",
|
|
102
103
|
"istanbul": "^1.1.0-alpha.1",
|
|
103
104
|
"jest": "^30.0.5",
|
|
104
105
|
"jest-codemods": "^0.34.2",
|
|
@@ -114,7 +115,7 @@
|
|
|
114
115
|
"tslib": "^2.8.1"
|
|
115
116
|
},
|
|
116
117
|
"scripts": {
|
|
117
|
-
"metadata:update:job": "git reset --hard && git pull && npm install && npm run metadata:update-and-release",
|
|
118
|
+
"metadata:update:job": "node build-scripts/check-for-uncommitted-files && git reset --hard && git pull && npm install && npm run metadata:update-and-release",
|
|
118
119
|
"metadata:update-and-release": "node build-scripts/pull-google-metadata ./PhoneNumberMetadata.xml ./metadata-info.json && node build-scripts/check-for-metadata-changes-and-release ./PhoneNumberMetadata.xml ./metadata-info.json",
|
|
119
120
|
"metadata:generate": "npm-run-all metadata:generate:min metadata:generate:full metadata:generate:max metadata:generate:mobile metadata:generate:min:js metadata:generate:full:js metadata:generate:max:js metadata:generate:mobile:js metadata:generate:mobile:examples:js",
|
|
120
121
|
"metadata:generate:min": "node build-scripts/generate-metadata-from-google-metadata ./PhoneNumberMetadata.xml ./metadata.min.json --examples mobile",
|
|
@@ -72,6 +72,8 @@ describe('isPossible', () => {
|
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', () => {
|
|
75
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
76
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
75
77
|
const phoneNumber = parsePhoneNumber('+13100000', undefined, metadata)
|
|
76
78
|
expect(phoneNumber.country).to.equal('CA')
|
|
77
79
|
expect(phoneNumber.isPossible()).to.equal(true)
|
|
@@ -25,6 +25,8 @@ describe('isPossiblePhoneNumber', () => {
|
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', () => {
|
|
28
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
29
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
28
30
|
expect(isPossiblePhoneNumber('+13100000', 'CA')).to.equal(true)
|
|
29
31
|
expect(isPossiblePhoneNumber('3100000', 'CA')).to.equal(true)
|
|
30
32
|
})
|
|
@@ -79,6 +79,9 @@ describe('parsePhoneNumber', () => {
|
|
|
79
79
|
})
|
|
80
80
|
|
|
81
81
|
it('should handle the cases when multiple countries share the same country calling code and a phone number is possible in non-"main" country and is not possible in the "main" country', () => {
|
|
82
|
+
// Tests that Californian numbers `+1310xxxx` are considered possible.
|
|
83
|
+
// https://gitlab.com/catamphetamine/react-phone-number-input/-/issues/228#note_1872536721
|
|
84
|
+
|
|
82
85
|
const phoneNumber = parsePhoneNumber('+13100000')
|
|
83
86
|
expect(phoneNumber.country).to.equal('CA')
|
|
84
87
|
expect(phoneNumber.isPossible()).to.equal(true)
|