libphonenumber-js 1.9.10 → 1.9.11
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 +9 -0
- package/README.md +74 -23
- package/build/AsYouTypeParser.js +5 -5
- package/build/AsYouTypeParser.js.map +1 -1
- package/build/isPossiblePhoneNumber.js +30 -0
- package/build/isPossiblePhoneNumber.js.map +1 -0
- package/build/isPossiblePhoneNumber.test.js +32 -0
- package/build/isPossiblePhoneNumber.test.js.map +1 -0
- package/build/isValidPhoneNumber.js +30 -0
- package/build/isValidPhoneNumber.js.map +1 -0
- package/build/isValidPhoneNumber.test.js +32 -0
- package/build/isValidPhoneNumber.test.js.map +1 -0
- package/build/parsePhoneNumberFromString.test.js +21 -0
- package/build/parsePhoneNumberFromString.test.js.map +1 -1
- package/build/parse_.js +13 -22
- package/build/parse_.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/core/index.commonjs.js +3 -0
- package/core/index.d.ts +7 -1
- package/core/index.js +3 -0
- package/custom.d.ts +1 -1
- package/custom.js +3 -1
- package/es6/AsYouTypeParser.js +5 -5
- package/es6/AsYouTypeParser.js.map +1 -1
- package/es6/isPossiblePhoneNumber.js +19 -0
- package/es6/isPossiblePhoneNumber.js.map +1 -0
- package/es6/isPossiblePhoneNumber.test.js +27 -0
- package/es6/isPossiblePhoneNumber.test.js.map +1 -0
- package/es6/isValidPhoneNumber.js +19 -0
- package/es6/isValidPhoneNumber.js.map +1 -0
- package/es6/isValidPhoneNumber.test.js +27 -0
- package/es6/isValidPhoneNumber.test.js.map +1 -0
- package/es6/parsePhoneNumberFromString.test.js +21 -0
- package/es6/parsePhoneNumberFromString.test.js.map +1 -1
- package/es6/parse_.js +14 -21
- package/es6/parse_.js.map +1 -1
- package/index.d.ts +4 -1
- package/index.es6.exports/isPossibleNumber.js +2 -0
- package/index.es6.exports/isValidNumber.js +2 -0
- package/index.es6.js +3 -0
- package/max/exports/isPossiblePhoneNumber.js +6 -0
- package/max/exports/isValidPhoneNumber.js +6 -0
- package/max/index.commonjs.js +8 -0
- package/max/index.js +3 -0
- package/min/exports/isPossiblePhoneNumber.js +6 -0
- package/min/exports/isValidPhoneNumber.js +6 -0
- package/min/index.commonjs.js +8 -0
- package/min/index.d.ts +4 -1
- package/min/index.js +3 -0
- package/mobile/exports/isPossiblePhoneNumber.js +6 -0
- package/mobile/exports/isValidPhoneNumber.js +6 -0
- package/mobile/index.commonjs.js +8 -0
- package/mobile/index.js +3 -0
- package/package.json +1 -1
- package/source/AsYouTypeParser.js +5 -5
- package/source/isPossiblePhoneNumber.js +12 -0
- package/source/isPossiblePhoneNumber.test.js +20 -0
- package/source/isValidPhoneNumber.js +12 -0
- package/source/isValidPhoneNumber.test.js +20 -0
- package/source/parsePhoneNumberFromString.test.js +17 -0
- package/source/parse_.js +12 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<!-- (breaking change) `parsePhoneNumberFromString()`: `extract: false` is now the default mode: non-phone-number characters aren't now trimmed on the left and on the right sides of a phone number. For example, `(213) 373-4253` is parsed as a valid phone number, but `Call: (213) 373-4253` is not, because `Call: ` doesn't automatically get trimmed now. For the old behavior, pass `extract: true` option. -->
|
|
2
|
+
|
|
1
3
|
<!--
|
|
2
4
|
The exported `Metadata` name is already used for exporting the "raw" JSON metadata type.
|
|
3
5
|
Then, `Metadata` class has become exported, but its name is already taken, so TypeScript users seem to be unable to use the `Metadata` class.
|
|
@@ -69,6 +71,13 @@ And edit the README:
|
|
|
69
71
|
|
|
70
72
|
<!-- (breaking change) Changed `countries` and `country_calling_codes` properties in metadata: now they're not properties but rather elements of an array (`countries` is an array now rather than an object; `countries` is `metadata[0]` and `country_calling_codes` is `metadata[1]`). If you were using a custom-generated metadata then it has to be re-generated for the new version. -->
|
|
71
73
|
|
|
74
|
+
1.9.11 / 10.02.2021
|
|
75
|
+
==================
|
|
76
|
+
|
|
77
|
+
* [Added](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/29) `extract: false` option on `parsePhoneNumberFromString()`: it enables a bit "stricter" parsing in a way that it attempts to parse the entire text as a phone number rather than extracting a phone number from text. For example, with `extract: false` option, `"(213) 373-4253"` is parsed as a valid phone number, but `"Call: (213) 373-4253"` is not, because the `"Call: "` part doesn't automatically get trimmed in this case. If there's version `2.x`, I guess `extract: false` will be the default behavior because it looks more appropriate than the default "extract" behavior of Google's `libphonenumber`.
|
|
78
|
+
|
|
79
|
+
* Added `isPossiblePhoneNumber()` and `isValidPhoneNumber()` functions, which are basically shortucts to `parsePhoneNumberFromString(text, { extract: false })` and then `.isValid()`/`.isPossible()`.
|
|
80
|
+
|
|
72
81
|
1.9.5 / 01.12.2020
|
|
73
82
|
==================
|
|
74
83
|
|
package/README.md
CHANGED
|
@@ -110,6 +110,17 @@ parseNumber('Phone: 8 (800) 555 35 35.', 'RU')
|
|
|
110
110
|
</details>
|
|
111
111
|
-->
|
|
112
112
|
|
|
113
|
+
### Validate phone number
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { isPossiblePhoneNumber, isValidPhoneNumber } from 'libphonenumber-js'
|
|
117
|
+
|
|
118
|
+
isPossiblePhoneNumber('8 (800) 555-35-35', 'RU') === true
|
|
119
|
+
isValidPhoneNumber('8 (800) 555-35-35', 'RU') === true
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
`isPossiblePhoneNumber()` only validates phone number length, while `isValidPhoneNumber()` validates both phone number length and the actual phone number digits.
|
|
123
|
+
|
|
113
124
|
### Format phone number
|
|
114
125
|
|
|
115
126
|
<!--
|
|
@@ -222,7 +233,19 @@ Sometimes (rarely) not all countries are needed, and in those cases developers m
|
|
|
222
233
|
|
|
223
234
|
### Country code
|
|
224
235
|
|
|
225
|
-
"
|
|
236
|
+
A "country code" is a [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (like `US`). <!-- or a special `001` country code used for ["non-geographic entities"](#non-geographic) (as per [Google's libphonenumber library](https://github.com/googlei18n/libphonenumber/blob/0068d861a68d3d4612f7bf8646ab844dd3cefce5/java/libphonenumber/test/com/google/i18n/phonenumbers/RegionCode.java#L23-L24)). -->
|
|
237
|
+
|
|
238
|
+
This library supports all [officially assigned](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) ISO alpha-2 country codes, plus a few extra ones like: `AC` ([Ascension Island](https://en.wikipedia.org/wiki/Ascension_Island)), `TA` ([Tristan da Cunha](https://en.wikipedia.org/wiki/Tristan_da_Cunha)), `XK` ([Kosovo](https://en.wikipedia.org/wiki/Kosovo)).
|
|
239
|
+
|
|
240
|
+
<!--
|
|
241
|
+
var countries = []
|
|
242
|
+
for (const code of Object.keys(country_calling_codes)) {
|
|
243
|
+
countries = countries.concat(country_calling_codes[code])
|
|
244
|
+
}
|
|
245
|
+
console.log(countries.length)
|
|
246
|
+
-->
|
|
247
|
+
|
|
248
|
+
To check whether a country code is supported, use [`isSupportedCountry()`](#issupportedcountrycountry-string-boolean) function.
|
|
226
249
|
|
|
227
250
|
### Non-geographic
|
|
228
251
|
|
|
@@ -269,9 +292,11 @@ Returns an instance of [`PhoneNumber`](#phonenumber) class, or `undefined` if no
|
|
|
269
292
|
|
|
270
293
|
Available `options`:
|
|
271
294
|
|
|
272
|
-
* `defaultCountry` — Default country for parsing national numbers. Instead of passing `options.defaultCountry` one could pass `defaultCountry` argument directly.
|
|
295
|
+
* `defaultCountry: string` — Default [country](#country-code) for parsing national numbers. Instead of passing `options.defaultCountry` one could pass `defaultCountry` argument directly.
|
|
273
296
|
|
|
274
|
-
* `defaultCallingCode` — Default calling code for parsing national numbers. Some numbering plans are for ["non-geographic numbering plans"](#non-geographic) and they don't have a country code, so `defaultCountry` can't be specified for them.
|
|
297
|
+
* `defaultCallingCode: string` — Default [calling code](#country-calling-code) for parsing national numbers. Some numbering plans are for ["non-geographic numbering plans"](#non-geographic) and they don't have a country code, so `defaultCountry` can't be specified for them.
|
|
298
|
+
|
|
299
|
+
* `extract: boolean` — Defines the ["strictness"](#strictness) of parsing a phone number.
|
|
275
300
|
|
|
276
301
|
If a developer wants to know the exact reason why the phone number couldn't be parsed then they can use `parsePhoneNumberWithError()` function which throws the exact error:
|
|
277
302
|
|
|
@@ -302,6 +327,22 @@ try {
|
|
|
302
327
|
* `TOO_SHORT` — When national (significant) number is too short (for ex. 1 digit).
|
|
303
328
|
</details>
|
|
304
329
|
|
|
330
|
+
#### Strictness
|
|
331
|
+
|
|
332
|
+
By default, the parsing function will attempt to extract a phone number from an input string even in cases like `"Support: (213) 373-4253 (robot)"`, which mimicks the behavior of the original Google's `libphonenumber` library, and is the default behavior for legacy reasons. However, if "strict" input validation is required, one can pass `extract: false` flag to demand that the whole input string be a viable phone number.
|
|
333
|
+
|
|
334
|
+
```js
|
|
335
|
+
parsePhoneNumber('Call: (213) 373-4253', 'US') === PhoneNumber
|
|
336
|
+
|
|
337
|
+
// When parsing the same string with `extract: false` flag,
|
|
338
|
+
// it will return `undefined`, because a phone number can't
|
|
339
|
+
// contain letters or a colon.
|
|
340
|
+
parsePhoneNumber('Call: (213) 373-4253', {
|
|
341
|
+
defaultCountry: 'US',
|
|
342
|
+
extract: false
|
|
343
|
+
}) === undefined
|
|
344
|
+
```
|
|
345
|
+
|
|
305
346
|
### `PhoneNumber`
|
|
306
347
|
|
|
307
348
|
<!--
|
|
@@ -360,7 +401,7 @@ phoneNumber.getURI() === phoneNumber.format("RFC3966")
|
|
|
360
401
|
|
|
361
402
|
#### `isPossible(): boolean`
|
|
362
403
|
|
|
363
|
-
Checks if the phone number is "possible". Only checks the phone number length, doesn't check the number digits against any regular expressions.
|
|
404
|
+
Checks if the phone number is "possible". Only checks the phone number length, doesn't check the actual phone number digits against any regular expressions.
|
|
364
405
|
|
|
365
406
|
#### `isValid(): boolean`
|
|
366
407
|
|
|
@@ -397,7 +438,7 @@ parseMobile('+6589555555').isValid() === false
|
|
|
397
438
|
|
|
398
439
|
####
|
|
399
440
|
|
|
400
|
-
See
|
|
441
|
+
See ["Using phone number validation feature"](#using-phone-number-validation-feature) for choosing between `isPossible()` and `isValid()`.
|
|
401
442
|
|
|
402
443
|
<!--
|
|
403
444
|
#### `isValidForRegion(country)`
|
|
@@ -467,13 +508,35 @@ Returns `true` if the number belongs to a ["non-geographic numbering plan"](#non
|
|
|
467
508
|
|
|
468
509
|
Compares two `PhoneNumber`s: returns `true` if they're equal, `false` otherwise.
|
|
469
510
|
|
|
511
|
+
### `isPossiblePhoneNumber(input: string): boolean`
|
|
512
|
+
|
|
513
|
+
Checks if `input` can be parsed as a "possible" phone number. A phone number is "possible" when it has valid length. The actual phone number digits aren't validated.
|
|
514
|
+
|
|
515
|
+
```js
|
|
516
|
+
isPossiblePhoneNumber('8 (888) 888-88-88', 'RU') === true
|
|
517
|
+
isPossiblePhoneNumber('+12223334444') === true
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
This function is just a shortcut for a two-step process of ["strictly"](#strictness) parsing a phone number and then calling `.isPossible()`.
|
|
521
|
+
|
|
522
|
+
### `isValidPhoneNumber(input: string): boolean`
|
|
523
|
+
|
|
524
|
+
Checks if `input` can be parsed as a "valid" phone number. A phone number is "valid" when it has valid length, and the actual phone number digits match the regular expressions for that country.
|
|
525
|
+
|
|
526
|
+
```js
|
|
527
|
+
isValidPhoneNumber('8 (800) 555-35-35', 'RU') === true
|
|
528
|
+
isValidPhoneNumber('+12133734253') === true
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
This function is just a shortcut for a two-step process of ["strictly"](#strictness) parsing a phone number and then calling `.isValid()`.
|
|
532
|
+
|
|
470
533
|
### `class` AsYouType([options or defaultCountry])
|
|
471
534
|
|
|
472
535
|
Creates a formatter for a partially entered phone number.
|
|
473
536
|
|
|
474
537
|
Available `options`:
|
|
475
538
|
|
|
476
|
-
* `defaultCountry` — Default country for parsing national numbers. Instead of passing `options.defaultCountry` one could pass `defaultCountry` argument directly.
|
|
539
|
+
* `defaultCountry` — Default [country](#country-code) for parsing national numbers. Instead of passing `options.defaultCountry` one could pass `defaultCountry` argument directly.
|
|
477
540
|
|
|
478
541
|
* `defaultCallingCode` — Default calling code for parsing national numbers. Some numbering plans are for ["non-geographic numbering plans"](#non-geographic) and they don't have a country code, so `defaultCountry` can't be specified for them.
|
|
479
542
|
|
|
@@ -592,7 +655,7 @@ Searches for phone numbers in `text`.
|
|
|
592
655
|
|
|
593
656
|
Available `options`:
|
|
594
657
|
|
|
595
|
-
* `defaultCountry` — Default country for parsing national numbers. Instead of passing `options.defaultCountry` one could pass `defaultCountry` argument directly.
|
|
658
|
+
* `defaultCountry` — Default [country](#country-code) for parsing national numbers. Instead of passing `options.defaultCountry` one could pass `defaultCountry` argument directly.
|
|
596
659
|
|
|
597
660
|
* `defaultCallingCode` — Default calling code for parsing national numbers. Some numbering plans are for ["non-geographic numbering plans"](#non-geographic) and they don't have a country code, so `defaultCountry` can't be specified for them.
|
|
598
661
|
|
|
@@ -738,7 +801,7 @@ phoneNumber.formatNational() === '8 (912) 345-67-89'
|
|
|
738
801
|
|
|
739
802
|
### isSupportedCountry(country: string): boolean
|
|
740
803
|
|
|
741
|
-
Checks if a country is supported by this library.
|
|
804
|
+
Checks if a [country](#country-code) is supported by this library.
|
|
742
805
|
|
|
743
806
|
```js
|
|
744
807
|
isSupportedCountry('RU') === true
|
|
@@ -766,7 +829,7 @@ getCountryCallingCode('IL') === '972'
|
|
|
766
829
|
|
|
767
830
|
### getExtPrefix(country: string): string
|
|
768
831
|
|
|
769
|
-
Returns phone number extension prefix for a given
|
|
832
|
+
Returns phone number extension prefix for a given [country](#country-code). If no custom ext prefix is defined for a `country` then the default `" ext. "` prefix is returned.
|
|
770
833
|
|
|
771
834
|
```js
|
|
772
835
|
getExtPrefix('US') === ' ext. '
|
|
@@ -1115,21 +1178,9 @@ isValidNumberForRegion('07624369230', 'IM') === true
|
|
|
1115
1178
|
|
|
1116
1179
|
## Using phone number validation feature
|
|
1117
1180
|
|
|
1118
|
-
I personally don't use strict phone number validation in my projects
|
|
1119
|
-
|
|
1120
|
-
* New phone number rules can be added to Google's `libphonenumber` library after they have already been implemented in real life (which can introduce a delay).
|
|
1121
|
-
|
|
1122
|
-
<!--
|
|
1123
|
-
* Then those new rules from Google's `libphonenumber` are updated automatically in this library (the scheduled update script introduces a small delay of 1 day, unless it malfunctions).
|
|
1124
|
-
-->
|
|
1125
|
-
|
|
1126
|
-
* After that those new rules from Google's `libphonenumber` are merged in this library (another delay).
|
|
1127
|
-
|
|
1128
|
-
* And then there's still the web application itself using this library and until a developer installs `libphonenumber-js@latest` manually and rebuilds and redeploys the web application, it's gonna use the old (potentially outdated) phone number validation rules which could result in losing rare customers with newly valid (but previously non-valid) phone numbers if a website form is too strict about validating user's input.
|
|
1129
|
-
|
|
1130
|
-
Phone number validation rules are [being updated regularly](https://github.com/googlei18n/libphonenumber/commits/master/resources/PhoneNumberMetadata.xml) in Google's repo. Imagine a web application (for example, a "promo-site" or a "personal website") with a "Contact Us" form being deployed once and then running for years without any maintenance.
|
|
1181
|
+
I personally don't use strict phone number validation in my projects. The rationale is that telephone numbering plans can and sometimes do change, meaning that [`PhoneNumber.isValid()`](#isvalid) function may one day become outdated on a website that isn't actively maintained anymore. Imagine a "promo-site" or a "personal website" being deployed once and then running for years without any maintenance, where a client may be unable to submit a simple "Contact Us" form just because this newly allocated pool of mobile phone numbers wasn't present in that old version of `libphonenumber-js` bundled in it.
|
|
1131
1182
|
|
|
1132
|
-
|
|
1183
|
+
Whenever there's a "business requirement" to validate a phone number that's being input by a user, I prefer using [`PhoneNumber.isPossible()`](#ispossible) instead of [`PhoneNumber.isValid()`](#isvalid), so that it just validates the phone number length, and doesn't validate the actual phone number digits. But it doesn't mean that you shouldn't use [`PhoneNumber.isValid()`](#isvalid) — maybe in your case it would make sense.
|
|
1133
1184
|
|
|
1134
1185
|
## React
|
|
1135
1186
|
|
package/build/AsYouTypeParser.js
CHANGED
|
@@ -34,9 +34,9 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
34
34
|
|
|
35
35
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
36
36
|
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
37
|
+
var VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART = '[' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']+';
|
|
38
|
+
var VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART + '$', 'i');
|
|
39
|
+
var VALID_FORMATTED_PHONE_NUMBER_PART = '(?:' + '[' + _constants.PLUS_CHARS + ']' + '[' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']*' + '|' + '[' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']+' + ')';
|
|
40
40
|
var AFTER_PHONE_NUMBER_DIGITS_END_PATTERN = new RegExp('[^' + _constants.VALID_PUNCTUATION + _constants.VALID_DIGITS + ']+' + '.*' + '$'); // Tests whether `national_prefix_for_parsing` could match
|
|
41
41
|
// different national prefixes.
|
|
42
42
|
// Matches anything that's not a digit or a square bracket.
|
|
@@ -441,7 +441,7 @@ exports["default"] = AsYouTypeParser;
|
|
|
441
441
|
|
|
442
442
|
function extractFormattedPhoneNumber(text) {
|
|
443
443
|
// Attempt to extract a possible number from the string passed in.
|
|
444
|
-
var startsAt = text.search(
|
|
444
|
+
var startsAt = text.search(VALID_FORMATTED_PHONE_NUMBER_PART);
|
|
445
445
|
|
|
446
446
|
if (startsAt < 0) {
|
|
447
447
|
return;
|
|
@@ -499,7 +499,7 @@ function extractFormattedDigitsAndPlus(text) {
|
|
|
499
499
|
// then parse phone number characters from a formatted phone number.
|
|
500
500
|
|
|
501
501
|
|
|
502
|
-
if (!
|
|
502
|
+
if (!VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART_PATTERN.test(formattedDigits)) {
|
|
503
503
|
formattedDigits = '';
|
|
504
504
|
}
|
|
505
505
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/AsYouTypeParser.js"],"names":["VALID_FORMATTED_PHONE_NUMBER_PART","VALID_PUNCTUATION","VALID_DIGITS","VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN","RegExp","VALID_PHONE_NUMBER","PLUS_CHARS","AFTER_PHONE_NUMBER_DIGITS_END_PATTERN","COMPLEX_NATIONAL_PREFIX","AsYouTypeParser","defaultCountry","defaultCallingCode","metadata","onNationalSignificantNumberChange","text","state","extractFormattedDigitsAndPlus","formattedDigits","hasPlus","digits","justLeadingPlus","startInternationalNumber","inputDigits","nextDigits","hasReceivedThreeLeadingDigits","length","appendDigits","extractIddPrefix","isWaitingForCountryCallingCode","extractCountryCallingCode","appendNationalSignificantNumberDigits","international","hasExtractedNationalSignificantNumber","extractNationalSignificantNumber","getNationalDigits","update","callingCode","getDigitsWithoutInternationalPrefix","countryCallingCode","number","setCallingCode","nationalSignificantNumber","numberingPlan","hasSelectedNumberingPlan","nationalPrefixForParsing","_nationalPrefixForParsing","couldPossiblyExtractAnotherNationalSignificantNumber","test","undefined","nationalDigits","setState","nationalPrefix","nationalNumber","carrierCode","onExtractedNationalNumber","prevNationalSignificantNumber","complexPrefixBeforeNationalSignificantNumber","nationalSignificantNumberMatchesInput","nationalSignificantNumberIndex","lastIndexOf","prefixBeforeNationalNumber","slice","extractAnotherNationalSignificantNumber","extractCallingCodeAndNationalSignificantNumber","fixMissingPlus","IDDPrefix","numberWithoutIDD","newCallingCode","missingPlus","resetNationalSignificantNumber","extractFormattedPhoneNumber","startsAt","search","replace","_extractFormattedDigitsAndPlus","extractedNumber"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;;AAMA,IAAMA,iCAAiC,GACtC,MACCC,4BADD,GAECC,uBAFD,GAGA,IAJD;AAMA,IAAMC,yCAAyC,GAAG,IAAIC,MAAJ,CAAW,MAAMJ,iCAAN,GAA0C,GAArD,EAA0D,GAA1D,CAAlD;AAEA,IAAMK,kBAAkB,GACvB,QACC,GADD,GACOC,qBADP,GACoB,GADpB,GAEC,GAFD,GAGEL,4BAHF,GAIEC,uBAJF,GAKC,IALD,GAMC,GAND,GAOC,GAPD,GAQED,4BARF,GASEC,uBATF,GAUC,IAVD,GAWA,GAZD;AAcA,IAAMK,qCAAqC,GAAG,IAAIH,MAAJ,CAC7C,OACCH,4BADD,GAECC,uBAFD,GAGA,IAHA,GAIA,IAJA,GAKA,GAN6C,CAA9C,C,CASA;AACA;AACA;;AACA,IAAMM,uBAAuB,GAAG,WAAhC;;IAEqBC,e;;;AACpB,iCAKG;AAAA,QAJFC,cAIE,QAJFA,cAIE;AAAA,QAHFC,kBAGE,QAHFA,kBAGE;AAAA,QAFFC,QAEE,QAFFA,QAEE;AAAA,QADFC,iCACE,QADFA,iCACE;;AAAA;;AACF,SAAKH,cAAL,GAAsBA,cAAtB;AACA,SAAKC,kBAAL,GAA0BA,kBAA1B;AACA,SAAKC,QAAL,GAAgBA,QAAhB;AACA,SAAKC,iCAAL,GAAyCA,iCAAzC;AACA;;;;0BAEKC,I,EAAMC,K,EAAO;AAAA,kCACiBC,6BAA6B,CAACF,IAAD,CAD9C;AAAA;AAAA,UACXG,eADW;AAAA,UACMC,OADN;;AAElB,UAAMC,MAAM,GAAG,6BAAYF,eAAZ,CAAf,CAFkB,CAGlB;;AACA,UAAIG,eAAJ;;AACA,UAAIF,OAAJ,EAAa;AACZ,YAAI,CAACH,KAAK,CAAC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8BAA8B,CAAC5D,IAAD,CADZ;AAAA;AAAA,MAC9CG,eAD8C;AAAA,MAC7BC,OAD6B,8BAEnD;AACA;AACA;;;AACA,MAAI,CAACf,yCAAyC,CAAC4C,IAA1C,CAA+C9B,eAA/C,CAAL,EAAsE;AACrEA,IAAAA,eAAe,GAAG,EAAlB;AACA;;AACD,SAAO,CAACA,eAAD,EAAkBC,OAAlB,CAAP;AACA","sourcesContent":["import extractCountryCallingCode from './helpers/extractCountryCallingCode'\r\nimport extractCountryCallingCodeFromInternationalNumberWithoutPlusSign from './helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign'\r\nimport extractNationalNumberFromPossiblyIncompleteNumber from './helpers/extractNationalNumberFromPossiblyIncompleteNumber'\r\nimport stripIddPrefix from './helpers/stripIddPrefix'\r\nimport parseDigits from './helpers/parseDigits'\r\n\r\nimport {\r\n\tVALID_DIGITS,\r\n\tVALID_PUNCTUATION,\r\n\tPLUS_CHARS\r\n} from './constants'\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_PART =\r\n\t'[' +\r\n\t\tVALID_PUNCTUATION +\r\n\t\tVALID_DIGITS +\r\n\t']+'\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_PART + '$', 'i')\r\n\r\nconst VALID_PHONE_NUMBER =\r\n\t'(?:' +\r\n\t\t'[' + PLUS_CHARS + ']' +\r\n\t\t'[' +\r\n\t\t\tVALID_PUNCTUATION +\r\n\t\t\tVALID_DIGITS +\r\n\t\t']*' +\r\n\t\t'|' +\r\n\t\t'[' +\r\n\t\t\tVALID_PUNCTUATION +\r\n\t\t\tVALID_DIGITS +\r\n\t\t']+' +\r\n\t')'\r\n\r\nconst AFTER_PHONE_NUMBER_DIGITS_END_PATTERN = new RegExp(\r\n\t'[^' +\r\n\t\tVALID_PUNCTUATION +\r\n\t\tVALID_DIGITS +\r\n\t']+' +\r\n\t'.*' +\r\n\t'$'\r\n)\r\n\r\n// Tests whether `national_prefix_for_parsing` could match\r\n// different national prefixes.\r\n// Matches anything that's not a digit or a square bracket.\r\nconst COMPLEX_NATIONAL_PREFIX = /[^\\d\\[\\]]/\r\n\r\nexport default class AsYouTypeParser {\r\n\tconstructor({\r\n\t\tdefaultCountry,\r\n\t\tdefaultCallingCode,\r\n\t\tmetadata,\r\n\t\tonNationalSignificantNumberChange\r\n\t}) {\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.metadata = metadata\r\n\t\tthis.onNationalSignificantNumberChange = onNationalSignificantNumberChange\r\n\t}\r\n\r\n\tinput(text, state) {\r\n\t\tconst [formattedDigits, hasPlus] = extractFormattedDigitsAndPlus(text)\r\n\t\tconst digits = parseDigits(formattedDigits)\r\n\t\t// Checks for a special case: just a leading `+` has been entered.\r\n\t\tlet justLeadingPlus\r\n\t\tif (hasPlus) {\r\n\t\t\tif (!state.digits) {\r\n\t\t\t\tstate.startInternationalNumber()\r\n\t\t\t\tif (!digits) {\r\n\t\t\t\t\tjustLeadingPlus = true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (digits) {\r\n\t\t\tthis.inputDigits(digits, state)\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number digits.\r\n\t * @param {string} digits\r\n\t * @return {string} [formattedNumber] Formatted national phone number (if it can be formatted at this stage). Returning `undefined` means \"don't format the national phone number at this stage\".\r\n\t */\r\n\tinputDigits(nextDigits, state) {\r\n\t\tconst { digits } = state\r\n\t\tconst hasReceivedThreeLeadingDigits = digits.length < 3 && digits.length + nextDigits.length >= 3\r\n\r\n\t\t// Append phone number digits.\r\n\t\tstate.appendDigits(nextDigits)\r\n\r\n\t\t// Attempt to extract IDD prefix:\r\n\t\t// Some users input their phone number in international format,\r\n\t\t// but in an \"out-of-country\" dialing format instead of using the leading `+`.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/185\r\n\t\t// Detect such numbers as soon as there're at least 3 digits.\r\n\t\t// Google's library attempts to extract IDD prefix at 3 digits,\r\n\t\t// so this library just copies that behavior.\r\n\t\t// I guess that's because the most commot IDD prefixes are\r\n\t\t// `00` (Europe) and `011` (US).\r\n\t\t// There exist really long IDD prefixes too:\r\n\t\t// for example, in Australia the default IDD prefix is `0011`,\r\n\t\t// and it could even be as long as `14880011`.\r\n\t\t// An IDD prefix is extracted here, and then every time when\r\n\t\t// there's a new digit and the number couldn't be formatted.\r\n\t\tif (hasReceivedThreeLeadingDigits) {\r\n\t\t\tthis.extractIddPrefix(state)\r\n\t\t}\r\n\r\n\t\tif (this.isWaitingForCountryCallingCode(state)) {\r\n\t\t\tif (!this.extractCountryCallingCode(state)) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tstate.appendNationalSignificantNumberDigits(nextDigits)\r\n\t\t}\r\n\r\n\t\t// If a phone number is being input in international format,\r\n\t\t// then it's not valid for it to have a national prefix.\r\n\t\t// Still, some people incorrectly input such numbers with a national prefix.\r\n\t\t// In such cases, only attempt to strip a national prefix if the number becomes too long.\r\n\t\t// (but that is done later, not here)\r\n\t\tif (!state.international) {\r\n\t\t\tif (!this.hasExtractedNationalSignificantNumber) {\r\n\t\t\t\tthis.extractNationalSignificantNumber(state.getNationalDigits(), state.update)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tisWaitingForCountryCallingCode({ international, callingCode }) {\r\n\t\treturn international && !callingCode\r\n\t}\r\n\r\n\t// Extracts a country calling code from a number\r\n\t// being entered in internatonal format.\r\n\textractCountryCallingCode(state) {\r\n\t\tconst { countryCallingCode, number } = extractCountryCallingCode(\r\n\t\t\t'+' + state.getDigitsWithoutInternationalPrefix(),\r\n\t\t\tthis.defaultCountry,\r\n\t\t\tthis.defaultCallingCode,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (countryCallingCode) {\r\n\t\t\tstate.setCallingCode(countryCallingCode)\r\n\t\t\tstate.update({\r\n\t\t\t\tnationalSignificantNumber: number\r\n\t\t\t})\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\treset(numberingPlan) {\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.hasSelectedNumberingPlan = true\r\n\t\t\tconst nationalPrefixForParsing = numberingPlan._nationalPrefixForParsing()\r\n\t\t\tthis.couldPossiblyExtractAnotherNationalSignificantNumber = nationalPrefixForParsing && COMPLEX_NATIONAL_PREFIX.test(nationalPrefixForParsing)\r\n\t\t} else {\r\n\t\t\tthis.hasSelectedNumberingPlan = undefined\r\n\t\t\tthis.couldPossiblyExtractAnotherNationalSignificantNumber = undefined\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Extracts a national (significant) number from user input.\r\n\t * Google's library is different in that it only applies `national_prefix_for_parsing`\r\n\t * and doesn't apply `national_prefix_transform_rule` after that.\r\n\t * https://github.com/google/libphonenumber/blob/a3d70b0487875475e6ad659af404943211d26456/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L539\r\n\t * @return {boolean} [extracted]\r\n\t */\r\n\textractNationalSignificantNumber(nationalDigits, setState) {\r\n\t\tif (!this.hasSelectedNumberingPlan) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst {\r\n\t\t\tnationalPrefix,\r\n\t\t\tnationalNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = extractNationalNumberFromPossiblyIncompleteNumber(\r\n\t\t\tnationalDigits,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t\tif (nationalNumber === nationalDigits) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.onExtractedNationalNumber(\r\n\t\t\tnationalPrefix,\r\n\t\t\tcarrierCode,\r\n\t\t\tnationalNumber,\r\n\t\t\tnationalDigits,\r\n\t\t\tsetState\r\n\t\t)\r\n\t\treturn true\r\n\t}\r\n\r\n\t/**\r\n\t * In Google's code this function is called \"attempt to extract longer NDD\".\r\n\t * \"Some national prefixes are a substring of others\", they say.\r\n\t * @return {boolean} [result] — Returns `true` if extracting a national prefix produced different results from what they were.\r\n\t */\r\n\textractAnotherNationalSignificantNumber(nationalDigits, prevNationalSignificantNumber, setState) {\r\n\t\tif (!this.hasExtractedNationalSignificantNumber) {\r\n\t\t\treturn this.extractNationalSignificantNumber(nationalDigits, setState)\r\n\t\t}\r\n\t\tif (!this.couldPossiblyExtractAnotherNationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst {\r\n\t\t\tnationalPrefix,\r\n\t\t\tnationalNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = extractNationalNumberFromPossiblyIncompleteNumber(\r\n\t\t\tnationalDigits,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t\t// If a national prefix has been extracted previously,\r\n\t\t// then it's always extracted as additional digits are added.\r\n\t\t// That's assuming `extractNationalNumberFromPossiblyIncompleteNumber()`\r\n\t\t// doesn't do anything different from what it currently does.\r\n\t\t// So, just in case, here's this check, though it doesn't occur.\r\n\t\t/* istanbul ignore if */\r\n\t\tif (nationalNumber === prevNationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.onExtractedNationalNumber(\r\n\t\t\tnationalPrefix,\r\n\t\t\tcarrierCode,\r\n\t\t\tnationalNumber,\r\n\t\t\tnationalDigits,\r\n\t\t\tsetState\r\n\t\t)\r\n\t\treturn true\r\n\t}\r\n\r\n\tonExtractedNationalNumber(\r\n\t\tnationalPrefix,\r\n\t\tcarrierCode,\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalDigits,\r\n\t\tsetState\r\n\t) {\r\n\t\tlet complexPrefixBeforeNationalSignificantNumber\r\n\t\tlet nationalSignificantNumberMatchesInput\r\n\t\t// This check also works with empty `this.nationalSignificantNumber`.\r\n\t\tconst nationalSignificantNumberIndex = nationalDigits.lastIndexOf(nationalSignificantNumber)\r\n\t\t// If the extracted national (significant) number is the\r\n\t\t// last substring of the `digits`, then it means that it hasn't been altered:\r\n\t\t// no digits have been removed from the national (significant) number\r\n\t\t// while applying `national_prefix_transform_rule`.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule\r\n\t\tif (nationalSignificantNumberIndex >= 0 &&\r\n\t\t\tnationalSignificantNumberIndex === nationalDigits.length - nationalSignificantNumber.length) {\r\n\t\t\tnationalSignificantNumberMatchesInput = true\r\n\t\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t\t// as just a basic national prefix, then such prefix is stored in\r\n\t\t\t// `this.complexPrefixBeforeNationalSignificantNumber` property and will be\r\n\t\t\t// prepended \"as is\" to the national (significant) number to produce\r\n\t\t\t// a formatted result.\r\n\t\t\tconst prefixBeforeNationalNumber = nationalDigits.slice(0, nationalSignificantNumberIndex)\r\n\t\t\t// `prefixBeforeNationalNumber` is always non-empty,\r\n\t\t\t// because `onExtractedNationalNumber()` isn't called\r\n\t\t\t// when a national (significant) number hasn't been actually \"extracted\":\r\n\t\t\t// when a national (significant) number is equal to the national part of `digits`,\r\n\t\t\t// then `onExtractedNationalNumber()` doesn't get called.\r\n\t\t\tif (prefixBeforeNationalNumber !== nationalPrefix) {\r\n\t\t\t\tcomplexPrefixBeforeNationalSignificantNumber = prefixBeforeNationalNumber\r\n\t\t\t}\r\n\t\t}\r\n\t\tsetState({\r\n\t\t\tnationalPrefix,\r\n\t\t\tcarrierCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tnationalSignificantNumberMatchesInput,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t\t})\r\n\t\t// `onExtractedNationalNumber()` is only called when\r\n\t\t// the national (significant) number actually did change.\r\n\t\tthis.hasExtractedNationalSignificantNumber = true\r\n\t\tthis.onNationalSignificantNumberChange()\r\n\t}\r\n\r\n\treExtractNationalSignificantNumber(state) {\r\n\t\t// Attempt to extract a national prefix.\r\n\t\t//\r\n\t\t// Some people incorrectly input national prefix\r\n\t\t// in an international phone number.\r\n\t\t// For example, some people write British phone numbers as `+44(0)...`.\r\n\t\t//\r\n\t\t// Also, in some rare cases, it is valid for a national prefix\r\n\t\t// to be a part of an international phone number.\r\n\t\t// For example, mobile phone numbers in Mexico are supposed to be\r\n\t\t// dialled internationally using a `1` national prefix,\r\n\t\t// so the national prefix will be part of an international number.\r\n\t\t//\r\n\t\t// Quote from:\r\n\t\t// https://www.mexperience.com/dialing-cell-phones-in-mexico/\r\n\t\t//\r\n\t\t// \"Dialing a Mexican cell phone from abroad\r\n\t\t// When you are calling a cell phone number in Mexico from outside Mexico,\r\n\t\t// it’s necessary to dial an additional “1” after Mexico’s country code\r\n\t\t// (which is “52”) and before the area code.\r\n\t\t// You also ignore the 045, and simply dial the area code and the\r\n\t\t// cell phone’s number.\r\n\t\t//\r\n\t\t// If you don’t add the “1”, you’ll receive a recorded announcement\r\n\t\t// asking you to redial using it.\r\n\t\t//\r\n\t\t// For example, if you are calling from the USA to a cell phone\r\n\t\t// in Mexico City, you would dial +52 – 1 – 55 – 1234 5678.\r\n\t\t// (Note that this is different to calling a land line in Mexico City\r\n\t\t// from abroad, where the number dialed would be +52 – 55 – 1234 5678)\".\r\n\t\t//\r\n\t\t// Google's demo output:\r\n\t\t// https://libphonenumber.appspot.com/phonenumberparser?number=%2b5215512345678&country=MX\r\n\t\t//\r\n\t\tif (this.extractAnotherNationalSignificantNumber(\r\n\t\t\tstate.getNationalDigits(),\r\n\t\t\tstate.nationalSignificantNumber,\r\n\t\t\tstate.update\r\n\t\t)) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// If no format matches the phone number, then it could be\r\n\t\t// \"a really long IDD\" (quote from a comment in Google's library).\r\n\t\t// An IDD prefix is first extracted when the user has entered at least 3 digits,\r\n\t\t// and then here — every time when there's a new digit and the number\r\n\t\t// couldn't be formatted.\r\n\t\t// For example, in Australia the default IDD prefix is `0011`,\r\n\t\t// and it could even be as long as `14880011`.\r\n\t\t//\r\n\t\t// Could also check `!hasReceivedThreeLeadingDigits` here\r\n\t\t// to filter out the case when this check duplicates the one\r\n\t\t// already performed when there're 3 leading digits,\r\n\t\t// but it's not a big deal, and in most cases there\r\n\t\t// will be a suitable `format` when there're 3 leading digits.\r\n\t\t//\r\n\t\tif (this.extractIddPrefix(state)) {\r\n\t\t\tthis.extractCallingCodeAndNationalSignificantNumber(state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// Google's AsYouType formatter supports sort of an \"autocorrection\" feature\r\n\t\t// when it \"autocorrects\" numbers that have been input for a country\r\n\t\t// with that country's calling code.\r\n\t\t// Such \"autocorrection\" feature looks weird, but different people have been requesting it:\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/375\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/316\r\n\t\tif (this.fixMissingPlus(state)) {\r\n\t\t\tthis.extractCallingCodeAndNationalSignificantNumber(state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\textractIddPrefix(state) {\r\n\t\t// An IDD prefix can't be present in a number written with a `+`.\r\n\t\t// Also, don't re-extract an IDD prefix if has already been extracted.\r\n\t\tconst {\r\n\t\t\tinternational,\r\n\t\t\tIDDPrefix,\r\n\t\t\tdigits,\r\n\t\t\tnationalSignificantNumber\r\n\t\t} = state\r\n\t\tif (international || IDDPrefix) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Some users input their phone number in \"out-of-country\"\r\n\t\t// dialing format instead of using the leading `+`.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/185\r\n\t\t// Detect such numbers.\r\n\t\tconst numberWithoutIDD = stripIddPrefix(\r\n\t\t\tdigits,\r\n\t\t\tthis.defaultCountry,\r\n\t\t\tthis.defaultCallingCode,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (numberWithoutIDD !== undefined && numberWithoutIDD !== digits) {\r\n\t\t\t// If an IDD prefix was stripped then convert the IDD-prefixed number\r\n\t\t\t// to international number for subsequent parsing.\r\n\t\t\tstate.update({\r\n\t\t\t\tIDDPrefix: digits.slice(0, digits.length - numberWithoutIDD.length)\r\n\t\t\t})\r\n\t\t\tthis.startInternationalNumber(state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tfixMissingPlus(state) {\r\n\t\tif (!state.international) {\r\n\t\t\tconst {\r\n\t\t\t\tcountryCallingCode: newCallingCode,\r\n\t\t\t\tnumber\r\n\t\t\t} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\t\t\t\tstate.digits,\r\n\t\t\t\tthis.defaultCountry,\r\n\t\t\t\tthis.defaultCallingCode,\r\n\t\t\t\tthis.metadata.metadata\r\n\t\t\t)\r\n\t\t\tif (newCallingCode) {\r\n\t\t\t\tstate.update({\r\n\t\t\t\t\tmissingPlus: true\r\n\t\t\t\t})\r\n\t\t\t\tthis.startInternationalNumber(state)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstartInternationalNumber(state) {\r\n\t\tstate.startInternationalNumber()\r\n\t\t// If a national (significant) number has been extracted before, reset it.\r\n\t\tif (state.nationalSignificantNumber) {\r\n\t\t\tstate.resetNationalSignificantNumber()\r\n\t\t\tthis.onNationalSignificantNumberChange()\r\n\t\t\tthis.hasExtractedNationalSignificantNumber = undefined\r\n\t\t}\r\n\t}\r\n\r\n\textractCallingCodeAndNationalSignificantNumber(state) {\r\n\t\tif (this.extractCountryCallingCode(state)) {\r\n\t\t\t// `this.extractCallingCode()` is currently called when the number\r\n\t\t\t// couldn't be formatted during the standard procedure.\r\n\t\t\t// Normally, the national prefix would be re-extracted\r\n\t\t\t// for an international number if such number couldn't be formatted,\r\n\t\t\t// but since it's already not able to be formatted,\r\n\t\t\t// there won't be yet another retry, so also extract national prefix here.\r\n\t\t\tthis.extractNationalSignificantNumber(state.getNationalDigits(), state.update)\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number from text (if there's any).\r\n * @param {string} text\r\n * @return {string} [formattedPhoneNumber]\r\n */\r\nfunction extractFormattedPhoneNumber(text) {\r\n\t// Attempt to extract a possible number from the string passed in.\r\n\tconst startsAt = text.search(VALID_PHONE_NUMBER)\r\n\tif (startsAt < 0) {\r\n\t\treturn\r\n\t}\r\n\t// Trim everything to the left of the phone number.\r\n\ttext = text.slice(startsAt)\r\n\t// Trim the `+`.\r\n\tlet hasPlus\r\n\tif (text[0] === '+') {\r\n\t\thasPlus = true\r\n\t\ttext = text.slice('+'.length)\r\n\t}\r\n\t// Trim everything to the right of the phone number.\r\n\ttext = text.replace(AFTER_PHONE_NUMBER_DIGITS_END_PATTERN, '')\r\n\t// Re-add the previously trimmed `+`.\r\n\tif (hasPlus) {\r\n\t\ttext = '+' + text\r\n\t}\r\n\treturn text\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number digits (and a `+`) from text (if there're any).\r\n * @param {string} text\r\n * @return {any[]}\r\n */\r\nfunction _extractFormattedDigitsAndPlus(text) {\r\n\t// Extract a formatted phone number part from text.\r\n\tconst extractedNumber = extractFormattedPhoneNumber(text) || ''\r\n\t// Trim a `+`.\r\n\tif (extractedNumber[0] === '+') {\r\n\t\treturn [extractedNumber.slice('+'.length), true]\r\n\t}\r\n\treturn [extractedNumber]\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number digits (and a `+`) from text (if there're any).\r\n * @param {string} text\r\n * @return {any[]}\r\n */\r\nexport function extractFormattedDigitsAndPlus(text) {\r\n\tlet [formattedDigits, hasPlus] = _extractFormattedDigitsAndPlus(text)\r\n\t// If the extracted phone number part\r\n\t// can possibly be a part of some valid phone number\r\n\t// then parse phone number characters from a formatted phone number.\r\n\tif (!VALID_FORMATTED_PHONE_NUMBER_PART_PATTERN.test(formattedDigits)) {\r\n\t\tformattedDigits = ''\r\n\t}\r\n\treturn [formattedDigits, hasPlus]\r\n}"],"file":"AsYouTypeParser.js"}
|
|
1
|
+
{"version":3,"sources":["../source/AsYouTypeParser.js"],"names":["VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART","VALID_PUNCTUATION","VALID_DIGITS","VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART_PATTERN","RegExp","VALID_FORMATTED_PHONE_NUMBER_PART","PLUS_CHARS","AFTER_PHONE_NUMBER_DIGITS_END_PATTERN","COMPLEX_NATIONAL_PREFIX","AsYouTypeParser","defaultCountry","defaultCallingCode","metadata","onNationalSignificantNumberChange","text","state","extractFormattedDigitsAndPlus","formattedDigits","hasPlus","digits","justLeadingPlus","startInternationalNumber","inputDigits","nextDigits","hasReceivedThreeLeadingDigits","length","appendDigits","extractIddPrefix","isWaitingForCountryCallingCode","extractCountryCallingCode","appendNationalSignificantNumberDigits","international","hasExtractedNationalSignificantNumber","extractNationalSignificantNumber","getNationalDigits","update","callingCode","getDigitsWithoutInternationalPrefix","countryCallingCode","number","setCallingCode","nationalSignificantNumber","numberingPlan","hasSelectedNumberingPlan","nationalPrefixForParsing","_nationalPrefixForParsing","couldPossiblyExtractAnotherNationalSignificantNumber","test","undefined","nationalDigits","setState","nationalPrefix","nationalNumber","carrierCode","onExtractedNationalNumber","prevNationalSignificantNumber","complexPrefixBeforeNationalSignificantNumber","nationalSignificantNumberMatchesInput","nationalSignificantNumberIndex","lastIndexOf","prefixBeforeNationalNumber","slice","extractAnotherNationalSignificantNumber","extractCallingCodeAndNationalSignificantNumber","fixMissingPlus","IDDPrefix","numberWithoutIDD","newCallingCode","missingPlus","resetNationalSignificantNumber","extractFormattedPhoneNumber","startsAt","search","replace","_extractFormattedDigitsAndPlus","extractedNumber"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;;AAMA,IAAMA,wCAAwC,GAC7C,MACCC,4BADD,GAECC,uBAFD,GAGA,IAJD;AAMA,IAA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eAAD,EAAkBC,OAAlB,CAAP;AACA","sourcesContent":["import extractCountryCallingCode from './helpers/extractCountryCallingCode'\r\nimport extractCountryCallingCodeFromInternationalNumberWithoutPlusSign from './helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign'\r\nimport extractNationalNumberFromPossiblyIncompleteNumber from './helpers/extractNationalNumberFromPossiblyIncompleteNumber'\r\nimport stripIddPrefix from './helpers/stripIddPrefix'\r\nimport parseDigits from './helpers/parseDigits'\r\n\r\nimport {\r\n\tVALID_DIGITS,\r\n\tVALID_PUNCTUATION,\r\n\tPLUS_CHARS\r\n} from './constants'\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART =\r\n\t'[' +\r\n\t\tVALID_PUNCTUATION +\r\n\t\tVALID_DIGITS +\r\n\t']+'\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART_PATTERN = new RegExp('^' + VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART + '$', 'i')\r\n\r\nconst VALID_FORMATTED_PHONE_NUMBER_PART =\r\n\t'(?:' +\r\n\t\t'[' + PLUS_CHARS + ']' +\r\n\t\t'[' +\r\n\t\t\tVALID_PUNCTUATION +\r\n\t\t\tVALID_DIGITS +\r\n\t\t']*' +\r\n\t\t'|' +\r\n\t\t'[' +\r\n\t\t\tVALID_PUNCTUATION +\r\n\t\t\tVALID_DIGITS +\r\n\t\t']+' +\r\n\t')'\r\n\r\nconst AFTER_PHONE_NUMBER_DIGITS_END_PATTERN = new RegExp(\r\n\t'[^' +\r\n\t\tVALID_PUNCTUATION +\r\n\t\tVALID_DIGITS +\r\n\t']+' +\r\n\t'.*' +\r\n\t'$'\r\n)\r\n\r\n// Tests whether `national_prefix_for_parsing` could match\r\n// different national prefixes.\r\n// Matches anything that's not a digit or a square bracket.\r\nconst COMPLEX_NATIONAL_PREFIX = /[^\\d\\[\\]]/\r\n\r\nexport default class AsYouTypeParser {\r\n\tconstructor({\r\n\t\tdefaultCountry,\r\n\t\tdefaultCallingCode,\r\n\t\tmetadata,\r\n\t\tonNationalSignificantNumberChange\r\n\t}) {\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.metadata = metadata\r\n\t\tthis.onNationalSignificantNumberChange = onNationalSignificantNumberChange\r\n\t}\r\n\r\n\tinput(text, state) {\r\n\t\tconst [formattedDigits, hasPlus] = extractFormattedDigitsAndPlus(text)\r\n\t\tconst digits = parseDigits(formattedDigits)\r\n\t\t// Checks for a special case: just a leading `+` has been entered.\r\n\t\tlet justLeadingPlus\r\n\t\tif (hasPlus) {\r\n\t\t\tif (!state.digits) {\r\n\t\t\t\tstate.startInternationalNumber()\r\n\t\t\t\tif (!digits) {\r\n\t\t\t\t\tjustLeadingPlus = true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (digits) {\r\n\t\t\tthis.inputDigits(digits, state)\r\n\t\t}\r\n\t\treturn {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number digits.\r\n\t * @param {string} digits\r\n\t * @return {string} [formattedNumber] Formatted national phone number (if it can be formatted at this stage). Returning `undefined` means \"don't format the national phone number at this stage\".\r\n\t */\r\n\tinputDigits(nextDigits, state) {\r\n\t\tconst { digits } = state\r\n\t\tconst hasReceivedThreeLeadingDigits = digits.length < 3 && digits.length + nextDigits.length >= 3\r\n\r\n\t\t// Append phone number digits.\r\n\t\tstate.appendDigits(nextDigits)\r\n\r\n\t\t// Attempt to extract IDD prefix:\r\n\t\t// Some users input their phone number in international format,\r\n\t\t// but in an \"out-of-country\" dialing format instead of using the leading `+`.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/185\r\n\t\t// Detect such numbers as soon as there're at least 3 digits.\r\n\t\t// Google's library attempts to extract IDD prefix at 3 digits,\r\n\t\t// so this library just copies that behavior.\r\n\t\t// I guess that's because the most commot IDD prefixes are\r\n\t\t// `00` (Europe) and `011` (US).\r\n\t\t// There exist really long IDD prefixes too:\r\n\t\t// for example, in Australia the default IDD prefix is `0011`,\r\n\t\t// and it could even be as long as `14880011`.\r\n\t\t// An IDD prefix is extracted here, and then every time when\r\n\t\t// there's a new digit and the number couldn't be formatted.\r\n\t\tif (hasReceivedThreeLeadingDigits) {\r\n\t\t\tthis.extractIddPrefix(state)\r\n\t\t}\r\n\r\n\t\tif (this.isWaitingForCountryCallingCode(state)) {\r\n\t\t\tif (!this.extractCountryCallingCode(state)) {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tstate.appendNationalSignificantNumberDigits(nextDigits)\r\n\t\t}\r\n\r\n\t\t// If a phone number is being input in international format,\r\n\t\t// then it's not valid for it to have a national prefix.\r\n\t\t// Still, some people incorrectly input such numbers with a national prefix.\r\n\t\t// In such cases, only attempt to strip a national prefix if the number becomes too long.\r\n\t\t// (but that is done later, not here)\r\n\t\tif (!state.international) {\r\n\t\t\tif (!this.hasExtractedNationalSignificantNumber) {\r\n\t\t\t\tthis.extractNationalSignificantNumber(state.getNationalDigits(), state.update)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tisWaitingForCountryCallingCode({ international, callingCode }) {\r\n\t\treturn international && !callingCode\r\n\t}\r\n\r\n\t// Extracts a country calling code from a number\r\n\t// being entered in internatonal format.\r\n\textractCountryCallingCode(state) {\r\n\t\tconst { countryCallingCode, number } = extractCountryCallingCode(\r\n\t\t\t'+' + state.getDigitsWithoutInternationalPrefix(),\r\n\t\t\tthis.defaultCountry,\r\n\t\t\tthis.defaultCallingCode,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (countryCallingCode) {\r\n\t\t\tstate.setCallingCode(countryCallingCode)\r\n\t\t\tstate.update({\r\n\t\t\t\tnationalSignificantNumber: number\r\n\t\t\t})\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\treset(numberingPlan) {\r\n\t\tif (numberingPlan) {\r\n\t\t\tthis.hasSelectedNumberingPlan = true\r\n\t\t\tconst nationalPrefixForParsing = numberingPlan._nationalPrefixForParsing()\r\n\t\t\tthis.couldPossiblyExtractAnotherNationalSignificantNumber = nationalPrefixForParsing && COMPLEX_NATIONAL_PREFIX.test(nationalPrefixForParsing)\r\n\t\t} else {\r\n\t\t\tthis.hasSelectedNumberingPlan = undefined\r\n\t\t\tthis.couldPossiblyExtractAnotherNationalSignificantNumber = undefined\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Extracts a national (significant) number from user input.\r\n\t * Google's library is different in that it only applies `national_prefix_for_parsing`\r\n\t * and doesn't apply `national_prefix_transform_rule` after that.\r\n\t * https://github.com/google/libphonenumber/blob/a3d70b0487875475e6ad659af404943211d26456/java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java#L539\r\n\t * @return {boolean} [extracted]\r\n\t */\r\n\textractNationalSignificantNumber(nationalDigits, setState) {\r\n\t\tif (!this.hasSelectedNumberingPlan) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst {\r\n\t\t\tnationalPrefix,\r\n\t\t\tnationalNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = extractNationalNumberFromPossiblyIncompleteNumber(\r\n\t\t\tnationalDigits,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t\tif (nationalNumber === nationalDigits) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.onExtractedNationalNumber(\r\n\t\t\tnationalPrefix,\r\n\t\t\tcarrierCode,\r\n\t\t\tnationalNumber,\r\n\t\t\tnationalDigits,\r\n\t\t\tsetState\r\n\t\t)\r\n\t\treturn true\r\n\t}\r\n\r\n\t/**\r\n\t * In Google's code this function is called \"attempt to extract longer NDD\".\r\n\t * \"Some national prefixes are a substring of others\", they say.\r\n\t * @return {boolean} [result] — Returns `true` if extracting a national prefix produced different results from what they were.\r\n\t */\r\n\textractAnotherNationalSignificantNumber(nationalDigits, prevNationalSignificantNumber, setState) {\r\n\t\tif (!this.hasExtractedNationalSignificantNumber) {\r\n\t\t\treturn this.extractNationalSignificantNumber(nationalDigits, setState)\r\n\t\t}\r\n\t\tif (!this.couldPossiblyExtractAnotherNationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tconst {\r\n\t\t\tnationalPrefix,\r\n\t\t\tnationalNumber,\r\n\t\t\tcarrierCode\r\n\t\t} = extractNationalNumberFromPossiblyIncompleteNumber(\r\n\t\t\tnationalDigits,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t\t// If a national prefix has been extracted previously,\r\n\t\t// then it's always extracted as additional digits are added.\r\n\t\t// That's assuming `extractNationalNumberFromPossiblyIncompleteNumber()`\r\n\t\t// doesn't do anything different from what it currently does.\r\n\t\t// So, just in case, here's this check, though it doesn't occur.\r\n\t\t/* istanbul ignore if */\r\n\t\tif (nationalNumber === prevNationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\tthis.onExtractedNationalNumber(\r\n\t\t\tnationalPrefix,\r\n\t\t\tcarrierCode,\r\n\t\t\tnationalNumber,\r\n\t\t\tnationalDigits,\r\n\t\t\tsetState\r\n\t\t)\r\n\t\treturn true\r\n\t}\r\n\r\n\tonExtractedNationalNumber(\r\n\t\tnationalPrefix,\r\n\t\tcarrierCode,\r\n\t\tnationalSignificantNumber,\r\n\t\tnationalDigits,\r\n\t\tsetState\r\n\t) {\r\n\t\tlet complexPrefixBeforeNationalSignificantNumber\r\n\t\tlet nationalSignificantNumberMatchesInput\r\n\t\t// This check also works with empty `this.nationalSignificantNumber`.\r\n\t\tconst nationalSignificantNumberIndex = nationalDigits.lastIndexOf(nationalSignificantNumber)\r\n\t\t// If the extracted national (significant) number is the\r\n\t\t// last substring of the `digits`, then it means that it hasn't been altered:\r\n\t\t// no digits have been removed from the national (significant) number\r\n\t\t// while applying `national_prefix_transform_rule`.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule\r\n\t\tif (nationalSignificantNumberIndex >= 0 &&\r\n\t\t\tnationalSignificantNumberIndex === nationalDigits.length - nationalSignificantNumber.length) {\r\n\t\t\tnationalSignificantNumberMatchesInput = true\r\n\t\t\t// If a prefix of a national (significant) number is not as simple\r\n\t\t\t// as just a basic national prefix, then such prefix is stored in\r\n\t\t\t// `this.complexPrefixBeforeNationalSignificantNumber` property and will be\r\n\t\t\t// prepended \"as is\" to the national (significant) number to produce\r\n\t\t\t// a formatted result.\r\n\t\t\tconst prefixBeforeNationalNumber = nationalDigits.slice(0, nationalSignificantNumberIndex)\r\n\t\t\t// `prefixBeforeNationalNumber` is always non-empty,\r\n\t\t\t// because `onExtractedNationalNumber()` isn't called\r\n\t\t\t// when a national (significant) number hasn't been actually \"extracted\":\r\n\t\t\t// when a national (significant) number is equal to the national part of `digits`,\r\n\t\t\t// then `onExtractedNationalNumber()` doesn't get called.\r\n\t\t\tif (prefixBeforeNationalNumber !== nationalPrefix) {\r\n\t\t\t\tcomplexPrefixBeforeNationalSignificantNumber = prefixBeforeNationalNumber\r\n\t\t\t}\r\n\t\t}\r\n\t\tsetState({\r\n\t\t\tnationalPrefix,\r\n\t\t\tcarrierCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tnationalSignificantNumberMatchesInput,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber\r\n\t\t})\r\n\t\t// `onExtractedNationalNumber()` is only called when\r\n\t\t// the national (significant) number actually did change.\r\n\t\tthis.hasExtractedNationalSignificantNumber = true\r\n\t\tthis.onNationalSignificantNumberChange()\r\n\t}\r\n\r\n\treExtractNationalSignificantNumber(state) {\r\n\t\t// Attempt to extract a national prefix.\r\n\t\t//\r\n\t\t// Some people incorrectly input national prefix\r\n\t\t// in an international phone number.\r\n\t\t// For example, some people write British phone numbers as `+44(0)...`.\r\n\t\t//\r\n\t\t// Also, in some rare cases, it is valid for a national prefix\r\n\t\t// to be a part of an international phone number.\r\n\t\t// For example, mobile phone numbers in Mexico are supposed to be\r\n\t\t// dialled internationally using a `1` national prefix,\r\n\t\t// so the national prefix will be part of an international number.\r\n\t\t//\r\n\t\t// Quote from:\r\n\t\t// https://www.mexperience.com/dialing-cell-phones-in-mexico/\r\n\t\t//\r\n\t\t// \"Dialing a Mexican cell phone from abroad\r\n\t\t// When you are calling a cell phone number in Mexico from outside Mexico,\r\n\t\t// it’s necessary to dial an additional “1” after Mexico’s country code\r\n\t\t// (which is “52”) and before the area code.\r\n\t\t// You also ignore the 045, and simply dial the area code and the\r\n\t\t// cell phone’s number.\r\n\t\t//\r\n\t\t// If you don’t add the “1”, you’ll receive a recorded announcement\r\n\t\t// asking you to redial using it.\r\n\t\t//\r\n\t\t// For example, if you are calling from the USA to a cell phone\r\n\t\t// in Mexico City, you would dial +52 – 1 – 55 – 1234 5678.\r\n\t\t// (Note that this is different to calling a land line in Mexico City\r\n\t\t// from abroad, where the number dialed would be +52 – 55 – 1234 5678)\".\r\n\t\t//\r\n\t\t// Google's demo output:\r\n\t\t// https://libphonenumber.appspot.com/phonenumberparser?number=%2b5215512345678&country=MX\r\n\t\t//\r\n\t\tif (this.extractAnotherNationalSignificantNumber(\r\n\t\t\tstate.getNationalDigits(),\r\n\t\t\tstate.nationalSignificantNumber,\r\n\t\t\tstate.update\r\n\t\t)) {\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// If no format matches the phone number, then it could be\r\n\t\t// \"a really long IDD\" (quote from a comment in Google's library).\r\n\t\t// An IDD prefix is first extracted when the user has entered at least 3 digits,\r\n\t\t// and then here — every time when there's a new digit and the number\r\n\t\t// couldn't be formatted.\r\n\t\t// For example, in Australia the default IDD prefix is `0011`,\r\n\t\t// and it could even be as long as `14880011`.\r\n\t\t//\r\n\t\t// Could also check `!hasReceivedThreeLeadingDigits` here\r\n\t\t// to filter out the case when this check duplicates the one\r\n\t\t// already performed when there're 3 leading digits,\r\n\t\t// but it's not a big deal, and in most cases there\r\n\t\t// will be a suitable `format` when there're 3 leading digits.\r\n\t\t//\r\n\t\tif (this.extractIddPrefix(state)) {\r\n\t\t\tthis.extractCallingCodeAndNationalSignificantNumber(state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t\t// Google's AsYouType formatter supports sort of an \"autocorrection\" feature\r\n\t\t// when it \"autocorrects\" numbers that have been input for a country\r\n\t\t// with that country's calling code.\r\n\t\t// Such \"autocorrection\" feature looks weird, but different people have been requesting it:\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/376\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/375\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/316\r\n\t\tif (this.fixMissingPlus(state)) {\r\n\t\t\tthis.extractCallingCodeAndNationalSignificantNumber(state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\textractIddPrefix(state) {\r\n\t\t// An IDD prefix can't be present in a number written with a `+`.\r\n\t\t// Also, don't re-extract an IDD prefix if has already been extracted.\r\n\t\tconst {\r\n\t\t\tinternational,\r\n\t\t\tIDDPrefix,\r\n\t\t\tdigits,\r\n\t\t\tnationalSignificantNumber\r\n\t\t} = state\r\n\t\tif (international || IDDPrefix) {\r\n\t\t\treturn\r\n\t\t}\r\n\t\t// Some users input their phone number in \"out-of-country\"\r\n\t\t// dialing format instead of using the leading `+`.\r\n\t\t// https://github.com/catamphetamine/libphonenumber-js/issues/185\r\n\t\t// Detect such numbers.\r\n\t\tconst numberWithoutIDD = stripIddPrefix(\r\n\t\t\tdigits,\r\n\t\t\tthis.defaultCountry,\r\n\t\t\tthis.defaultCallingCode,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (numberWithoutIDD !== undefined && numberWithoutIDD !== digits) {\r\n\t\t\t// If an IDD prefix was stripped then convert the IDD-prefixed number\r\n\t\t\t// to international number for subsequent parsing.\r\n\t\t\tstate.update({\r\n\t\t\t\tIDDPrefix: digits.slice(0, digits.length - numberWithoutIDD.length)\r\n\t\t\t})\r\n\t\t\tthis.startInternationalNumber(state)\r\n\t\t\treturn true\r\n\t\t}\r\n\t}\r\n\r\n\tfixMissingPlus(state) {\r\n\t\tif (!state.international) {\r\n\t\t\tconst {\r\n\t\t\t\tcountryCallingCode: newCallingCode,\r\n\t\t\t\tnumber\r\n\t\t\t} = extractCountryCallingCodeFromInternationalNumberWithoutPlusSign(\r\n\t\t\t\tstate.digits,\r\n\t\t\t\tthis.defaultCountry,\r\n\t\t\t\tthis.defaultCallingCode,\r\n\t\t\t\tthis.metadata.metadata\r\n\t\t\t)\r\n\t\t\tif (newCallingCode) {\r\n\t\t\t\tstate.update({\r\n\t\t\t\t\tmissingPlus: true\r\n\t\t\t\t})\r\n\t\t\t\tthis.startInternationalNumber(state)\r\n\t\t\t\treturn true\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tstartInternationalNumber(state) {\r\n\t\tstate.startInternationalNumber()\r\n\t\t// If a national (significant) number has been extracted before, reset it.\r\n\t\tif (state.nationalSignificantNumber) {\r\n\t\t\tstate.resetNationalSignificantNumber()\r\n\t\t\tthis.onNationalSignificantNumberChange()\r\n\t\t\tthis.hasExtractedNationalSignificantNumber = undefined\r\n\t\t}\r\n\t}\r\n\r\n\textractCallingCodeAndNationalSignificantNumber(state) {\r\n\t\tif (this.extractCountryCallingCode(state)) {\r\n\t\t\t// `this.extractCallingCode()` is currently called when the number\r\n\t\t\t// couldn't be formatted during the standard procedure.\r\n\t\t\t// Normally, the national prefix would be re-extracted\r\n\t\t\t// for an international number if such number couldn't be formatted,\r\n\t\t\t// but since it's already not able to be formatted,\r\n\t\t\t// there won't be yet another retry, so also extract national prefix here.\r\n\t\t\tthis.extractNationalSignificantNumber(state.getNationalDigits(), state.update)\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number from text (if there's any).\r\n * @param {string} text\r\n * @return {string} [formattedPhoneNumber]\r\n */\r\nfunction extractFormattedPhoneNumber(text) {\r\n\t// Attempt to extract a possible number from the string passed in.\r\n\tconst startsAt = text.search(VALID_FORMATTED_PHONE_NUMBER_PART)\r\n\tif (startsAt < 0) {\r\n\t\treturn\r\n\t}\r\n\t// Trim everything to the left of the phone number.\r\n\ttext = text.slice(startsAt)\r\n\t// Trim the `+`.\r\n\tlet hasPlus\r\n\tif (text[0] === '+') {\r\n\t\thasPlus = true\r\n\t\ttext = text.slice('+'.length)\r\n\t}\r\n\t// Trim everything to the right of the phone number.\r\n\ttext = text.replace(AFTER_PHONE_NUMBER_DIGITS_END_PATTERN, '')\r\n\t// Re-add the previously trimmed `+`.\r\n\tif (hasPlus) {\r\n\t\ttext = '+' + text\r\n\t}\r\n\treturn text\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number digits (and a `+`) from text (if there're any).\r\n * @param {string} text\r\n * @return {any[]}\r\n */\r\nfunction _extractFormattedDigitsAndPlus(text) {\r\n\t// Extract a formatted phone number part from text.\r\n\tconst extractedNumber = extractFormattedPhoneNumber(text) || ''\r\n\t// Trim a `+`.\r\n\tif (extractedNumber[0] === '+') {\r\n\t\treturn [extractedNumber.slice('+'.length), true]\r\n\t}\r\n\treturn [extractedNumber]\r\n}\r\n\r\n/**\r\n * Extracts formatted phone number digits (and a `+`) from text (if there're any).\r\n * @param {string} text\r\n * @return {any[]}\r\n */\r\nexport function extractFormattedDigitsAndPlus(text) {\r\n\tlet [formattedDigits, hasPlus] = _extractFormattedDigitsAndPlus(text)\r\n\t// If the extracted phone number part\r\n\t// can possibly be a part of some valid phone number\r\n\t// then parse phone number characters from a formatted phone number.\r\n\tif (!VALID_FORMATTED_PHONE_NUMBER_DIGITS_PART_PATTERN.test(formattedDigits)) {\r\n\t\tformattedDigits = ''\r\n\t}\r\n\treturn [formattedDigits, hasPlus]\r\n}"],"file":"AsYouTypeParser.js"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = isPossiblePhoneNumber;
|
|
7
|
+
|
|
8
|
+
var _parsePhoneNumber = require("./parsePhoneNumber");
|
|
9
|
+
|
|
10
|
+
var _parsePhoneNumberFromString_ = _interopRequireDefault(require("./parsePhoneNumberFromString_"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
15
|
+
|
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
|
|
18
|
+
function isPossiblePhoneNumber() {
|
|
19
|
+
var _normalizeArguments = (0, _parsePhoneNumber.normalizeArguments)(arguments),
|
|
20
|
+
text = _normalizeArguments.text,
|
|
21
|
+
options = _normalizeArguments.options,
|
|
22
|
+
metadata = _normalizeArguments.metadata;
|
|
23
|
+
|
|
24
|
+
options = _objectSpread({}, options, {
|
|
25
|
+
extract: false
|
|
26
|
+
});
|
|
27
|
+
var phoneNumber = (0, _parsePhoneNumberFromString_["default"])(text, options, metadata);
|
|
28
|
+
return phoneNumber && phoneNumber.isPossible() || false;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=isPossiblePhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../source/isPossiblePhoneNumber.js"],"names":["isPossiblePhoneNumber","arguments","text","options","metadata","extract","phoneNumber","isPossible"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAEe,SAASA,qBAAT,GAAiC;AAAA,4BACb,0CAAmBC,SAAnB,CADa;AAAA,MACzCC,IADyC,uBACzCA,IADyC;AAAA,MACnCC,OADmC,uBACnCA,OADmC;AAAA,MAC1BC,QAD0B,uBAC1BA,QAD0B;;AAE/CD,EAAAA,OAAO,qBACHA,OADG;AAENE,IAAAA,OAAO,EAAE;AAFH,IAAP;AAIA,MAAMC,WAAW,GAAG,6CAA2BJ,IAA3B,EAAiCC,OAAjC,EAA0CC,QAA1C,CAApB;AACA,SAAOE,WAAW,IAAIA,WAAW,CAACC,UAAZ,EAAf,IAA2C,KAAlD;AACA","sourcesContent":["import { normalizeArguments } from './parsePhoneNumber'\r\nimport parsePhoneNumberFromString from './parsePhoneNumberFromString_'\r\n\r\nexport default function isPossiblePhoneNumber() {\r\n\tlet { text, options, metadata } = normalizeArguments(arguments)\r\n\toptions = {\r\n\t\t...options,\r\n\t\textract: false\r\n\t}\r\n\tconst phoneNumber = parsePhoneNumberFromString(text, options, metadata)\r\n\treturn phoneNumber && phoneNumber.isPossible() || false\r\n}"],"file":"isPossiblePhoneNumber.js"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _isPossiblePhoneNumber2 = _interopRequireDefault(require("./isPossiblePhoneNumber"));
|
|
4
|
+
|
|
5
|
+
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
+
|
|
9
|
+
function isPossiblePhoneNumber() {
|
|
10
|
+
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
11
|
+
parameters[_key] = arguments[_key];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
parameters.push(_metadataMin["default"]);
|
|
15
|
+
return _isPossiblePhoneNumber2["default"].apply(this, parameters);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('isPossiblePhoneNumber', function () {
|
|
19
|
+
it('should detect whether a phone number is possible', function () {
|
|
20
|
+
isPossiblePhoneNumber('8 (800) 555 35 35', 'RU').should.equal(true);
|
|
21
|
+
isPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU').should.equal(false);
|
|
22
|
+
isPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU').should.equal(false);
|
|
23
|
+
isPossiblePhoneNumber('8 (800) 555 35 35', {
|
|
24
|
+
defaultCountry: 'RU'
|
|
25
|
+
}).should.equal(true);
|
|
26
|
+
isPossiblePhoneNumber('+7 (800) 555 35 35').should.equal(true);
|
|
27
|
+
isPossiblePhoneNumber('+7 1 (800) 555 35 35').should.equal(false);
|
|
28
|
+
isPossiblePhoneNumber(' +7 (800) 555 35 35').should.equal(false);
|
|
29
|
+
isPossiblePhoneNumber(' ').should.equal(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=isPossiblePhoneNumber.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../source/isPossiblePhoneNumber.test.js"],"names":["isPossiblePhoneNumber","parameters","push","metadata","_isPossiblePhoneNumber","apply","describe","it","should","equal","defaultCountry"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,qBAAT,GAA8C;AAAA,oCAAZC,UAAY;AAAZA,IAAAA,UAAY;AAAA;;AAC7CA,EAAAA,UAAU,CAACC,IAAX,CAAgBC,uBAAhB;AACA,SAAOC,mCAAuBC,KAAvB,CAA6B,IAA7B,EAAmCJ,UAAnC,CAAP;AACA;;AAEDK,QAAQ,CAAC,uBAAD,EAA0B,YAAM;AACvCC,EAAAA,EAAE,CAAC,kDAAD,EAAqD,YAAM;AAC5DP,IAAAA,qBAAqB,CAAC,mBAAD,EAAsB,IAAtB,CAArB,CAAiDQ,MAAjD,CAAwDC,KAAxD,CAA8D,IAA9D;AACAT,IAAAA,qBAAqB,CAAC,qBAAD,EAAwB,IAAxB,CAArB,CAAmDQ,MAAnD,CAA0DC,KAA1D,CAAgE,KAAhE;AACAT,IAAAA,qBAAqB,CAAC,yBAAD,EAA4B,IAA5B,CAArB,CAAuDQ,MAAvD,CAA8DC,KAA9D,CAAoE,KAApE;AACAT,IAAAA,qBAAqB,CAAC,mBAAD,EAAsB;AAAEU,MAAAA,cAAc,EAAE;AAAlB,KAAtB,CAArB,CAAqEF,MAArE,CAA4EC,KAA5E,CAAkF,IAAlF;AACAT,IAAAA,qBAAqB,CAAC,oBAAD,CAArB,CAA4CQ,MAA5C,CAAmDC,KAAnD,CAAyD,IAAzD;AACAT,IAAAA,qBAAqB,CAAC,sBAAD,CAArB,CAA8CQ,MAA9C,CAAqDC,KAArD,CAA2D,KAA3D;AACAT,IAAAA,qBAAqB,CAAC,qBAAD,CAArB,CAA6CQ,MAA7C,CAAoDC,KAApD,CAA0D,KAA1D;AACAT,IAAAA,qBAAqB,CAAC,GAAD,CAArB,CAA2BQ,MAA3B,CAAkCC,KAAlC,CAAwC,KAAxC;AACA,GATC,CAAF;AAUA,CAXO,CAAR","sourcesContent":["import _isPossiblePhoneNumber from './isPossiblePhoneNumber'\r\nimport metadata from '../metadata.min.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\tisPossiblePhoneNumber('8 (800) 555 35 35', 'RU').should.equal(true)\r\n\t\tisPossiblePhoneNumber('8 (800) 555 35 35 0', 'RU').should.equal(false)\r\n\t\tisPossiblePhoneNumber('Call: 8 (800) 555 35 35', 'RU').should.equal(false)\r\n\t\tisPossiblePhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' }).should.equal(true)\r\n\t\tisPossiblePhoneNumber('+7 (800) 555 35 35').should.equal(true)\r\n\t\tisPossiblePhoneNumber('+7 1 (800) 555 35 35').should.equal(false)\r\n\t\tisPossiblePhoneNumber(' +7 (800) 555 35 35').should.equal(false)\r\n\t\tisPossiblePhoneNumber(' ').should.equal(false)\r\n\t})\r\n})"],"file":"isPossiblePhoneNumber.test.js"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = isValidPhoneNumber;
|
|
7
|
+
|
|
8
|
+
var _parsePhoneNumber = require("./parsePhoneNumber");
|
|
9
|
+
|
|
10
|
+
var _parsePhoneNumberFromString_ = _interopRequireDefault(require("./parsePhoneNumberFromString_"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
15
|
+
|
|
16
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
|
|
18
|
+
function isValidPhoneNumber() {
|
|
19
|
+
var _normalizeArguments = (0, _parsePhoneNumber.normalizeArguments)(arguments),
|
|
20
|
+
text = _normalizeArguments.text,
|
|
21
|
+
options = _normalizeArguments.options,
|
|
22
|
+
metadata = _normalizeArguments.metadata;
|
|
23
|
+
|
|
24
|
+
options = _objectSpread({}, options, {
|
|
25
|
+
extract: false
|
|
26
|
+
});
|
|
27
|
+
var phoneNumber = (0, _parsePhoneNumberFromString_["default"])(text, options, metadata);
|
|
28
|
+
return phoneNumber && phoneNumber.isValid() || false;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=isValidPhoneNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../source/isValidPhoneNumber.js"],"names":["isValidPhoneNumber","arguments","text","options","metadata","extract","phoneNumber","isValid"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;AAEe,SAASA,kBAAT,GAA8B;AAAA,4BACV,0CAAmBC,SAAnB,CADU;AAAA,MACtCC,IADsC,uBACtCA,IADsC;AAAA,MAChCC,OADgC,uBAChCA,OADgC;AAAA,MACvBC,QADuB,uBACvBA,QADuB;;AAE5CD,EAAAA,OAAO,qBACHA,OADG;AAENE,IAAAA,OAAO,EAAE;AAFH,IAAP;AAIA,MAAMC,WAAW,GAAG,6CAA2BJ,IAA3B,EAAiCC,OAAjC,EAA0CC,QAA1C,CAApB;AACA,SAAOE,WAAW,IAAIA,WAAW,CAACC,OAAZ,EAAf,IAAwC,KAA/C;AACA","sourcesContent":["import { normalizeArguments } from './parsePhoneNumber'\r\nimport parsePhoneNumberFromString from './parsePhoneNumberFromString_'\r\n\r\nexport default function isValidPhoneNumber() {\r\n\tlet { text, options, metadata } = normalizeArguments(arguments)\r\n\toptions = {\r\n\t\t...options,\r\n\t\textract: false\r\n\t}\r\n\tconst phoneNumber = parsePhoneNumberFromString(text, options, metadata)\r\n\treturn phoneNumber && phoneNumber.isValid() || false\r\n}"],"file":"isValidPhoneNumber.js"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _isValidPhoneNumber2 = _interopRequireDefault(require("./isValidPhoneNumber"));
|
|
4
|
+
|
|
5
|
+
var _metadataMin = _interopRequireDefault(require("../metadata.min.json"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
8
|
+
|
|
9
|
+
function isValidPhoneNumber() {
|
|
10
|
+
for (var _len = arguments.length, parameters = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
11
|
+
parameters[_key] = arguments[_key];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
parameters.push(_metadataMin["default"]);
|
|
15
|
+
return _isValidPhoneNumber2["default"].apply(this, parameters);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('isValidPhoneNumber', function () {
|
|
19
|
+
it('should detect whether a phone number is valid', function () {
|
|
20
|
+
isValidPhoneNumber('8 (800) 555 35 35', 'RU').should.equal(true);
|
|
21
|
+
isValidPhoneNumber('8 (800) 555 35 35 0', 'RU').should.equal(false);
|
|
22
|
+
isValidPhoneNumber('Call: 8 (800) 555 35 35', 'RU').should.equal(false);
|
|
23
|
+
isValidPhoneNumber('8 (800) 555 35 35', {
|
|
24
|
+
defaultCountry: 'RU'
|
|
25
|
+
}).should.equal(true);
|
|
26
|
+
isValidPhoneNumber('+7 (800) 555 35 35').should.equal(true);
|
|
27
|
+
isValidPhoneNumber('+7 1 (800) 555 35 35').should.equal(false);
|
|
28
|
+
isValidPhoneNumber(' +7 (800) 555 35 35').should.equal(false);
|
|
29
|
+
isValidPhoneNumber(' ').should.equal(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=isValidPhoneNumber.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../source/isValidPhoneNumber.test.js"],"names":["isValidPhoneNumber","parameters","push","metadata","_isValidPhoneNumber","apply","describe","it","should","equal","defaultCountry"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,kBAAT,GAA2C;AAAA,oCAAZC,UAAY;AAAZA,IAAAA,UAAY;AAAA;;AAC1CA,EAAAA,UAAU,CAACC,IAAX,CAAgBC,uBAAhB;AACA,SAAOC,gCAAoBC,KAApB,CAA0B,IAA1B,EAAgCJ,UAAhC,CAAP;AACA;;AAEDK,QAAQ,CAAC,oBAAD,EAAuB,YAAM;AACpCC,EAAAA,EAAE,CAAC,+CAAD,EAAkD,YAAM;AACzDP,IAAAA,kBAAkB,CAAC,mBAAD,EAAsB,IAAtB,CAAlB,CAA8CQ,MAA9C,CAAqDC,KAArD,CAA2D,IAA3D;AACAT,IAAAA,kBAAkB,CAAC,qBAAD,EAAwB,IAAxB,CAAlB,CAAgDQ,MAAhD,CAAuDC,KAAvD,CAA6D,KAA7D;AACAT,IAAAA,kBAAkB,CAAC,yBAAD,EAA4B,IAA5B,CAAlB,CAAoDQ,MAApD,CAA2DC,KAA3D,CAAiE,KAAjE;AACAT,IAAAA,kBAAkB,CAAC,mBAAD,EAAsB;AAAEU,MAAAA,cAAc,EAAE;AAAlB,KAAtB,CAAlB,CAAkEF,MAAlE,CAAyEC,KAAzE,CAA+E,IAA/E;AACAT,IAAAA,kBAAkB,CAAC,oBAAD,CAAlB,CAAyCQ,MAAzC,CAAgDC,KAAhD,CAAsD,IAAtD;AACAT,IAAAA,kBAAkB,CAAC,sBAAD,CAAlB,CAA2CQ,MAA3C,CAAkDC,KAAlD,CAAwD,KAAxD;AACAT,IAAAA,kBAAkB,CAAC,qBAAD,CAAlB,CAA0CQ,MAA1C,CAAiDC,KAAjD,CAAuD,KAAvD;AACAT,IAAAA,kBAAkB,CAAC,GAAD,CAAlB,CAAwBQ,MAAxB,CAA+BC,KAA/B,CAAqC,KAArC;AACA,GATC,CAAF;AAUA,CAXO,CAAR","sourcesContent":["import _isValidPhoneNumber from './isValidPhoneNumber'\r\nimport metadata from '../metadata.min.json'\r\n\r\nfunction isValidPhoneNumber(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _isValidPhoneNumber.apply(this, parameters)\r\n}\r\n\r\ndescribe('isValidPhoneNumber', () => {\r\n\tit('should detect whether a phone number is valid', () => {\r\n\t\tisValidPhoneNumber('8 (800) 555 35 35', 'RU').should.equal(true)\r\n\t\tisValidPhoneNumber('8 (800) 555 35 35 0', 'RU').should.equal(false)\r\n\t\tisValidPhoneNumber('Call: 8 (800) 555 35 35', 'RU').should.equal(false)\r\n\t\tisValidPhoneNumber('8 (800) 555 35 35', { defaultCountry: 'RU' }).should.equal(true)\r\n\t\tisValidPhoneNumber('+7 (800) 555 35 35').should.equal(true)\r\n\t\tisValidPhoneNumber('+7 1 (800) 555 35 35').should.equal(false)\r\n\t\tisValidPhoneNumber(' +7 (800) 555 35 35').should.equal(false)\r\n\t\tisValidPhoneNumber(' ').should.equal(false)\r\n\t})\r\n})"],"file":"isValidPhoneNumber.test.js"}
|
|
@@ -60,5 +60,26 @@ describe('parsePhoneNumberFromString', function () {
|
|
|
60
60
|
var phoneNumber2 = parsePhoneNumberFromString('+8707731116321');
|
|
61
61
|
phoneNumber2.isPossible().should.equal(false);
|
|
62
62
|
});
|
|
63
|
+
it('should support `extract: false` flag', function () {
|
|
64
|
+
var testCorrectness = function testCorrectness(number, expectedResult) {
|
|
65
|
+
var result = expect(parsePhoneNumberFromString(number, {
|
|
66
|
+
extract: false,
|
|
67
|
+
defaultCountry: 'US'
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
if (expectedResult) {
|
|
71
|
+
result.to.not.be.undefined;
|
|
72
|
+
} else {
|
|
73
|
+
result.to.be.undefined;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
testCorrectness('Call: (213) 373-4253', false);
|
|
78
|
+
testCorrectness('(213) 373-4253x', false);
|
|
79
|
+
testCorrectness('(213) 373-4253', true);
|
|
80
|
+
testCorrectness('- (213) 373-4253 -', true);
|
|
81
|
+
testCorrectness('+1 (213) 373-4253', true);
|
|
82
|
+
testCorrectness(' +1 (213) 373-4253', false);
|
|
83
|
+
});
|
|
63
84
|
});
|
|
64
85
|
//# sourceMappingURL=parsePhoneNumberFromString.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../source/parsePhoneNumberFromString.test.js"],"names":["parsePhoneNumberFromString","parameters","push","metadata","_parsePhoneNumberFromString","apply","USE_NON_GEOGRAPHIC_COUNTRY_CODE","describe","it","nationalNumber","should","equal","expect","to","be","undefined","phoneNumber","number","country","countryCallingCode","defaultCallingCode","isPossible","phoneNumber2"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,0BAAT,GAAmD;AAAA,oCAAZC,UAAY;AAAZA,IAAAA,UAAY;AAAA;;AAClDA,EAAAA,UAAU,CAACC,IAAX,CAAgBC,uBAAhB;AACA,SAAOC,wCAA4BC,KAA5B,CAAkC,IAAlC,EAAwCJ,UAAxC,CAAP;AACA;;AAED,IAAMK,+BAA+B,GAAG,KAAxC;AAEAC,QAAQ,CAAC,4BAAD,EAA+B,YAAM;AAC5CC,EAAAA,EAAE,CAAC,wCAAD,EAA2C,YAAM;AAClDR,IAAAA,0BAA0B,CAAC,2BAAD,EAA8B,IAA9B,CAA1B,CAA8DS,cAA9D,CAA6EC,MAA7E,CAAoFC,KAApF,CAA0F,YAA1F;AACAC,IAAAA,MAAM,CAACZ,0BAA0B,CAAC,GAAD,EAAM,IAAN,CAA3B,CAAN,CAA8Ca,EAA9C,CAAiDC,EAAjD,CAAoDC,SAApD;AACA,GAHC,CAAF;AAKAP,EAAAA,EAAE,CAAC,2BAAD,EAA8B,YAAM;AACrCI,IAAAA,MAAM,CAACZ,0BAA0B,CAAC,EAAD,CAA3B,CAAN,CAAuCa,EAAvC,CAA0CC,EAA1C,CAA6CC,SAA7C;AACA,GAFC,CAAF;AAIAP,EAAAA,EAAE,CAAC,gEAAD,EAAmE,YAAM;AAC1ER,IAAAA,0BAA0B,CAAC,4BAAD,EAA+B,IAA/B,CAA1B,CAA+DS,cAA/D,CAA8EC,MAA9E,CAAqFC,KAArF,CAA2F,YAA3F;AACAC,IAAAA,MAAM,CAACZ,0BAA0B,CAAC,2BAAD,EAA8B,IAA9B,CAA3B,CAAN,CAAsEa,EAAtE,CAAyEC,EAAzE,CAA4EC,SAA5E;AACA,GAHC,CAAF;AAMAP,EAAAA,EAAE,CAAC,qEAAD,EAAwE,YAAM;AAC/E,QAAMQ,WAAW,GA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B,IAAAA,YAAY,CAACD,UAAb,GAA0BX,MAA1B,CAAiCC,KAAjC,CAAuC,KAAvC;AACA,GALC,CAAF;
|
|
1
|
+
{"version":3,"sources":["../source/parsePhoneNumberFromString.test.js"],"names":["parsePhoneNumberFromString","parameters","push","metadata","_parsePhoneNumberFromString","apply","USE_NON_GEOGRAPHIC_COUNTRY_CODE","describe","it","nationalNumber","should","equal","expect","to","be","undefined","phoneNumber","number","country","countryCallingCode","defaultCallingCode","isPossible","phoneNumber2","testCorrectness","expectedResult","result","extract","defaultCountry","not"],"mappings":";;AAAA;;AACA;;;;AAEA,SAASA,0BAAT,GAAmD;AAAA,oCAAZC,UAAY;AAAZA,IAAAA,UAAY;AAAA;;AAClDA,EAAAA,UAAU,CAACC,IAAX,CAAgBC,uBAAhB;AACA,SAAOC,wCAA4BC,KAA5B,CAAkC,IAAlC,EAAwCJ,UAAxC,CAAP;AACA;;AAED,IAAMK,+BAA+B,GAAG,KAAxC;AAEAC,QAAQ,CAAC,4BAAD,EAA+B,YAAM;AAC5CC,EAAAA,EAAE,CAAC,wCAAD,EAA2C,YAAM;AAClDR,IAAAA,0BAA0B,CAAC,2BAAD,EAA8B,IAA9B,CAA1B,CAA8DS,cAA9D,CAA6EC,MAA7E,CAAoFC,KAApF,CAA0F,YAA1F;AACAC,IAAAA,MAAM,CAACZ,0BAA0B,CAAC,GAAD,EAAM,IAAN,CAA3B,CAAN,CAA8Ca,EAA9C,CAAiDC,EAAjD,CAAoDC,SAApD;AACA,GAHC,CAAF;AAKAP,EAAAA,EAAE,CAAC,2BAAD,EAA8B,YAAM;AACrCI,IAAAA,MAAM,CAACZ,0BAA0B,CAAC,EAAD,CAA3B,CAAN,CAAuCa,EAAvC,CAA0CC,EAA1C,CAA6CC,SAA7C;AACA,GAFC,CAAF;AAIAP,EAAAA,EAAE,CAAC,gEAAD,EAAmE,YAAM;AAC1ER,IAAAA,0BAA0B,CAAC,4BAAD,EAA+B,IAA/B,CAA1B,CAA+DS,cAA/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ata.min.json'\r\n\r\nfunction parsePhoneNumberFromString(...parameters) {\r\n\tparameters.push(metadata)\r\n\treturn _parsePhoneNumberFromString.apply(this, parameters)\r\n}\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\ndescribe('parsePhoneNumberFromString', () => {\r\n\tit('should parse phone numbers from string', () => {\r\n\t\tparsePhoneNumberFromString('Phone: 8 (800) 555 35 35.', 'RU').nationalNumber.should.equal('8005553535')\r\n\t\texpect(parsePhoneNumberFromString('3', 'RU')).to.be.undefined\r\n\t})\r\n\r\n\tit('should work in edge cases', () => {\r\n\t\texpect(parsePhoneNumberFromString('')).to.be.undefined\r\n\t})\r\n\r\n\tit('should parse phone numbers when invalid country code is passed', () => {\r\n\t\tparsePhoneNumberFromString('Phone: +7 (800) 555 35 35.', 'XX').nationalNumber.should.equal('8005553535')\r\n\t\texpect(parsePhoneNumberFromString('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 = parsePhoneNumberFromString('+870773111632')\r\n\t\tphoneNumber.number.should.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\tphoneNumber.country.should.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\tphoneNumber.countryCallingCode.should.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 = parsePhoneNumberFromString('773111632', { defaultCallingCode: '870' })\r\n\t\tphoneNumber.number.should.equal('+870773111632')\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\tphoneNumber.country.should.equal('001')\r\n\t\t} else {\r\n\t\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\t}\r\n\t\tphoneNumber.countryCallingCode.should.equal('870')\r\n\t})\r\n\r\n\tit('should determine the possibility of non-geographic phone numbers', () => {\r\n\t\tconst phoneNumber = parsePhoneNumberFromString('+870773111632')\r\n\t\tphoneNumber.isPossible().should.equal(true)\r\n\t\tconst phoneNumber2 = parsePhoneNumberFromString('+8707731116321')\r\n\t\tphoneNumber2.isPossible().should.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(parsePhoneNumberFromString(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"],"file":"parsePhoneNumberFromString.test.js"}
|