libphonenumber-js 1.10.16 → 1.10.17
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 +5 -0
- package/METADATA.md +17 -9
- package/README.md +17 -11
- package/build/AsYouType.js +4 -1
- package/build/AsYouType.js.map +1 -1
- package/build/AsYouTypeState.js +4 -2
- package/build/AsYouTypeState.js.map +1 -1
- package/build/PhoneNumber.js +11 -0
- package/build/PhoneNumber.js.map +1 -1
- package/build/PhoneNumber.test.js +44 -0
- package/build/PhoneNumber.test.js.map +1 -1
- package/build/helpers/getCountryByCallingCode.js +3 -38
- package/build/helpers/getCountryByCallingCode.js.map +1 -1
- package/build/helpers/getCountryByNationalNumber.js +46 -0
- package/build/helpers/getCountryByNationalNumber.js.map +1 -0
- package/build/helpers/getPossibleCountriesForNumber.js +44 -0
- package/build/helpers/getPossibleCountriesForNumber.js.map +1 -0
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/AsYouType.js +4 -1
- package/es6/AsYouType.js.map +1 -1
- package/es6/AsYouTypeState.js +4 -2
- package/es6/AsYouTypeState.js.map +1 -1
- package/es6/PhoneNumber.js +10 -0
- package/es6/PhoneNumber.js.map +1 -1
- package/es6/PhoneNumber.test.js +44 -0
- package/es6/PhoneNumber.test.js.map +1 -1
- package/es6/helpers/getCountryByCallingCode.js +3 -37
- package/es6/helpers/getCountryByCallingCode.js.map +1 -1
- package/es6/helpers/getCountryByNationalNumber.js +35 -0
- package/es6/helpers/getCountryByNationalNumber.js.map +1 -0
- package/es6/helpers/getPossibleCountriesForNumber.js +35 -0
- package/es6/helpers/getPossibleCountriesForNumber.js.map +1 -0
- package/package.json +1 -1
- package/source/AsYouType.js +4 -1
- package/source/AsYouTypeState.js +2 -2
- package/source/PhoneNumber.js +12 -0
- package/source/PhoneNumber.test.js +54 -0
- package/source/helpers/getCountryByCallingCode.js +2 -27
- package/source/helpers/getCountryByNationalNumber.js +26 -0
- package/source/helpers/getPossibleCountriesForNumber.js +28 -0
- package/types.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -67,6 +67,11 @@ And edit the README:
|
|
|
67
67
|
|
|
68
68
|
This changelog [only](https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/16#note_594165443) mentions the changes in the code. See [Google's changelog](https://github.com/google/libphonenumber/blob/master/release_notes.txt) for metadata changes.
|
|
69
69
|
|
|
70
|
+
1.10.17 / 08.01.2023
|
|
71
|
+
==================
|
|
72
|
+
|
|
73
|
+
* [Added](https://github.com/catamphetamine/libphonenumber-js/issues/420) `PhoneNumber.getPossibleCountries()` function. It returns a list of countries this phone number could possibly belong to. Can be used when parsing complete international phone numbers containing a "calling code" that is shared between several countries. If parsing such a phone number returns `country: undefined` then `getPossibleCountries()` function could be used to somehow speculate about what country could this phone number possibly belong to.
|
|
74
|
+
|
|
70
75
|
1.10.0 / 18.05.2022
|
|
71
76
|
==================
|
|
72
77
|
|
package/METADATA.md
CHANGED
|
@@ -28,17 +28,25 @@ Localized `" ext. "` prefix for this country. For example, in Russia it's `" д
|
|
|
28
28
|
|
|
29
29
|
### `leading_digits`
|
|
30
30
|
|
|
31
|
-
National (significant) number "leading digits" pattern. It's only defined for about 20% of the countries, most
|
|
31
|
+
National (significant) number "leading digits" pattern. It's only defined for about 20% of the countries, and in most cases it's for resolving ambiguity in cases when there're groups of countries sharing the same "country calling code". Although, if there's a group of countries sharing the same "country calling code", it doesn't necessarily mean that those countries have a `leading_digits` pattern defined.
|
|
32
32
|
|
|
33
|
-
For example, USA and Canada share the same `1` country calling code, but neither of them have a `leading_digits` pattern defined. On the other hand, Antigua and Barbuda also shares the same `1` country calling code, and its `leading_digits` pattern is `"268"`, so if an international phone number starts with `+1268` then it's certain that it belongs to Antigua and Barbuda, so "leading digits" are, in some cases, a
|
|
33
|
+
For example, USA and Canada share the same `1` country calling code, but neither of them have a `leading_digits` pattern defined. On the other hand, Antigua and Barbuda also shares the same `1` country calling code, and its `leading_digits` pattern is `"268"`, so if an international phone number starts with `+1268` then it's certain that it belongs to Antigua and Barbuda, so "leading digits" are, in some cases, a quick way of determining which one of the countries sharing the same country calling code does a phone number belong to.
|
|
34
34
|
|
|
35
|
-
While in most cases a `leading_digits` pattern is a sequence of digits like `"268"` for Antigua and Barbuda, in
|
|
35
|
+
While in most cases a `leading_digits` pattern is a sequence of digits like `"268"` for Antigua and Barbuda, in other cases it's a pattern like `"8001|8[024]9"` for Dominican Republic.
|
|
36
36
|
|
|
37
|
-
Overall, `leading_digits` patterns are only used as a performance speed-up trick when determining which country a phone number belongs to
|
|
37
|
+
Overall, `leading_digits` patterns are only used as a performance speed-up trick when determining which country a phone number belongs to: the check is still simpler than looking for a match against all of the precise phone number digit patterns of every country sharing a given country calling code.
|
|
38
38
|
|
|
39
|
-
For that reason, matching a `leading_digits` pattern is a sufficient but not necessary condition for a phone number to belong to
|
|
39
|
+
For that reason, matching a `leading_digits` pattern is a sufficient but not a necessary condition for a phone number to belong to a country: if a `leading_digits` pattern exists and a phone number matches it that it's certain that the phone number belongs to the country, and no other country. But, if there's no `leading_digits` pattern, or if the phone number doesn't match the `leading_digits` pattern, then it doesn't mean that the phone number doesn't belong to the country.
|
|
40
40
|
|
|
41
|
-
For example, "toll free" numbers starting with `800` are valid for all countries having `1` country calling code, so it doesn't make sense to include `800` in their `leading_digits` patterns. But
|
|
41
|
+
For example, "toll free" numbers starting with `800` are valid for all countries having `1` country calling code, so it doesn't make sense to include `800` in their `leading_digits` patterns. But one could say that those "toll free" numbers could be thought of as an unrelated edge case that can be ignored if the application only deals with human phone numbers.
|
|
42
|
+
|
|
43
|
+
Another example of phone number that're not included in `leading_digits` patters are ["personal"](https://en.wikipedia.org/wiki/Personal_Communications_Service) (satellite) numbers that start with [`5xx`](https://en.wikipedia.org/wiki/Personal_communications_service_(NANP)) for `+1` calling code.
|
|
44
|
+
|
|
45
|
+
<!-- https://www.nationalnanpa.com/number_resource_info/5XX_codes.html -->
|
|
46
|
+
|
|
47
|
+
The last example are mobile phone numbers which sometimes have identical patterns across the countries sharing the same "country calling code". An example are Finland (`FI`) and Åland Islands (`AX`) which share the same `+358` calling code and the same pattern for mobile phone numbers. And while [`+358 457 XXX XXXX`](https://en.wikipedia.org/wiki/Telephone_numbers_in_Åland) mobile numbers could belong both to Finland or Åland Islands, Åland Islands' `leading_digits` pattern is just `18` which doesn't include any mobile numbers at all.
|
|
48
|
+
|
|
49
|
+
So `leading_digits` patterns could only be used for a quick "positive" check and they can't be used for ruling out any countries.
|
|
42
50
|
|
|
43
51
|
### `national_number_pattern`
|
|
44
52
|
|
|
@@ -54,7 +62,7 @@ Other national prefix examples: `1` in US, `0` in France and UK, `8` in Russia.
|
|
|
54
62
|
|
|
55
63
|
### `national_prefix_for_parsing` / `national_prefix_transform_rule`
|
|
56
64
|
|
|
57
|
-
`national_prefix_for_parsing` is used to parse a [national (significant) number](https://
|
|
65
|
+
`national_prefix_for_parsing` is used to parse a [national (significant) number](https://gitlab.com/catamphetamine/libphonenumber-js#national-significant-number) from a phone number. Contrary to its name, `national_prefix_for_parsing` is used not just for parsing a "national prefix" out of a phone number (just `national_prefix` property would be sufficient for that), but also for parsing any other possible phone number prefixes out of a phone number, if there're any, and for any other cases like fixing a missing area code. So it's actually not a "national prefix for parsing", but rather a "national (significant) number extraction mechanism".
|
|
58
66
|
|
|
59
67
|
`national_prefix_for_parsing` is a regular expression that could (or could not) have some ["capturing groups"](https://www.regular-expressions.info/refcapture.html). If there're any "capturing groups", then `national_prefix_for_parsing` is accompanied by `national_prefix_transform_rule`: yet another incorrect name by Google, because `national_prefix_transform_rule` is not a "rule for transforming a national prefix", but rather a "template to transform the captured groups into a national (significant) number".
|
|
60
68
|
|
|
@@ -78,7 +86,7 @@ Whatever national prefix has been extracted, it's not used anywhere: instead, `n
|
|
|
78
86
|
|
|
79
87
|
### `types`
|
|
80
88
|
|
|
81
|
-
Regular expressions for all possible phone number types
|
|
89
|
+
Regular expressions for all possible phone number [types](https://gitlab.com/catamphetamine/libphonenumber-js#gettype-string) for this country: `fixed_line`, `mobile`, `toll_free`, `premium_rate`, etc.
|
|
82
90
|
|
|
83
91
|
#### `type` `pattern`
|
|
84
92
|
|
|
@@ -140,6 +148,6 @@ For example, Google's `libphonenumber` has `formatNumberForMobileDialing()` func
|
|
|
140
148
|
|
|
141
149
|
## Non-geographic
|
|
142
150
|
|
|
143
|
-
There're [calling codes](https://
|
|
151
|
+
There're [calling codes](https://gitlab.com/catamphetamine/libphonenumber-js#non-geographic) that don't correspond to any country. For example, "Global Mobile Satellite System" (`+881`). Such phone numbering systems are called "non-geographic entities" in Google's code. These "non-geographic entitites" reside in their own `nonGeographic` property, analogous to the `countries` property. `nonGeographic` is an object with keys being calling codes of the corresponding "non-geographic entities", and values being same as the values of the `countries` property.
|
|
144
152
|
|
|
145
153
|
"Non-geographic" numbering plans don't have [`possible_lengths`](#possible-lengths).
|
package/README.md
CHANGED
|
@@ -539,6 +539,12 @@ Is just an alias for `this.isValid() && this.country === country`.
|
|
|
539
539
|
https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion
|
|
540
540
|
-->
|
|
541
541
|
|
|
542
|
+
#### `getPossibleCountries(): string[]`
|
|
543
|
+
|
|
544
|
+
Returns a list of countries this phone number could possibly belong to.
|
|
545
|
+
|
|
546
|
+
Can be used when parsing complete international phone numbers containing a "calling code" that is shared between several countries. If parsing such a phone number returns `country: undefined` then `getPossibleCountries()` function could be used to somehow speculate about what country could this phone number possibly belong to.
|
|
547
|
+
|
|
542
548
|
#### `getType(): string?`
|
|
543
549
|
|
|
544
550
|
Returns phone number type (fixed line, mobile, toll free, etc) or `undefined` (if the number is invalid or if there are no phone number type regular expressions for this country in metadata).
|
|
@@ -550,17 +556,17 @@ By default the library uses "minimal" metadata which is only 75 kilobytes in siz
|
|
|
550
556
|
|
|
551
557
|
####
|
|
552
558
|
|
|
553
|
-
* `MOBILE`
|
|
554
|
-
* `FIXED_LINE`
|
|
555
|
-
* `FIXED_LINE_OR_MOBILE`
|
|
556
|
-
* `PREMIUM_RATE`
|
|
557
|
-
* `TOLL_FREE`
|
|
558
|
-
* `SHARED_COST`
|
|
559
|
-
* `VOIP`
|
|
560
|
-
* `PERSONAL_NUMBER`
|
|
561
|
-
* `PAGER`
|
|
562
|
-
* `UAN`
|
|
563
|
-
* `VOICEMAIL`
|
|
559
|
+
* `MOBILE` — Cellphones.
|
|
560
|
+
* `FIXED_LINE` — Stationary phones.
|
|
561
|
+
* `FIXED_LINE_OR_MOBILE` — Could be `MOBILE` or `FIXED_LINE`.
|
|
562
|
+
* [`PREMIUM_RATE`](https://en.wikipedia.org/wiki/Premium-rate_telephone_number) — Callers are charged by call or per minute. SMS text messages are also subject to charge.
|
|
563
|
+
* [`TOLL_FREE`](https://en.wikipedia.org/wiki/Toll-free_telephone_number) — Free to call from anywhere.
|
|
564
|
+
* [`SHARED_COST`](https://en.wikipedia.org/wiki/Shared-cost_service) — "An intermediate level of telephone call billing where the charge for calling a particular international or long-distance phone number is partially, but not entirely, paid for by the recipient".
|
|
565
|
+
* [`VOIP`](https://en.wikipedia.org/wiki/Voice_over_IP) — "IP telephony". Calls are made over the Internet rather than via the conventional telephone-only lines.
|
|
566
|
+
* [`PERSONAL_NUMBER`](https://en.wikipedia.org/wiki/Personal_Communications_Service) — Phones connected by satellites.
|
|
567
|
+
* [`PAGER`](https://en.wikipedia.org/wiki/Pager) — "Pagers" are wireless telecommunications devices that were widely used in the 80-es and could receive (and, optionally, send) text or voice messages.
|
|
568
|
+
* [`UAN`](https://www.pta.gov.pk/media/num/faqs_110208.pdf) — "UAN is a number resource that allows a service or business with several terminating lines to be reached through a unique universal number. A UAN number shall be dialable from the entire Pakistan, based on the applicant’s proposed coverage without dialing the area code. UAN cannot be assigned to two separate business or mutually exclusive public services. Each service provider who allows UAN through its network shall offer a tariff, which is not more expensive than the normal tariff available for a similar non-UAN public service".
|
|
569
|
+
* [`VOICEMAIL`](https://www.easytechjunkie.com/what-is-a-voicemail-access-number.htm) — "A voicemail access number is a telephone number provided by a [voicemail](https://en.wikipedia.org/wiki/Voicemail) service to allow subscribers to dial into their voicemail accounts and manage any currently saved messages. Typically, the number is used when a subscriber is away from home and wishes to check any voice messages currently stored on the service. Originally envisioned as part of the features associated with voicemail accounts offered with land line accounts, many mobile service providers today also supply their customers with a voicemail access number to use when checking messages from any phone other than the mobile or cellular unit associated with the account".
|
|
564
570
|
</details>
|
|
565
571
|
|
|
566
572
|
####
|
package/build/AsYouType.js
CHANGED
|
@@ -179,7 +179,10 @@ var AsYouType = /*#__PURE__*/function () {
|
|
|
179
179
|
_this.formatter.reset(_this.metadata.numberingPlan, _this.state);
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
|
-
this.state.reset(
|
|
182
|
+
this.state.reset({
|
|
183
|
+
country: this.defaultCountry,
|
|
184
|
+
callingCode: this.defaultCallingCode
|
|
185
|
+
});
|
|
183
186
|
this.formattedOutput = '';
|
|
184
187
|
return this;
|
|
185
188
|
}
|
package/build/AsYouType.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsYouType.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","Metadata","getCountryAndCallingCode","defaultCountry","defaultCallingCode","reset","hasCountry","undefined","isNonGeographicCallingCode","text","parser","input","state","digits","justLeadingPlus","formattedOutput","determineTheCountryIfNeeded","nationalSignificantNumber","formatter","narrowDownMatchingFormats","formattedNationalNumber","hasSelectedNumberingPlan","format","reExtractNationalSignificantNumber","nationalDigits","getNationalDigits","getFullNumber","getNonFormattedNumber","AsYouTypeState","onCountryChange","country","onCallingCodeChange","callingCode","selectNumberingPlan","numberingPlan","AsYouTypeFormatter","AsYouTypeParser","onNationalSignificantNumberChange","international","isInternational","getCallingCode","_getCountry","isCountryCallingCodeAmbiguous","determineTheCountry","prefix","getInternationalPrefixBeforeCountryCallingCode","spacing","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","nationalPrefix","number","nationalSignificantNumberMatchesInput","getNonFormattedNationalNumberWithPrefix","replace","DIGIT_PLACEHOLDER","countryCodes","getCountryCodesForCallingCode","length","setCountry","getCountryByCallingCode","callingCode_","countryCallingCode","carrierCode","phoneNumber","PhoneNumber","getNumber","isPossible","isValid","getTemplate","getNonFormattedTemplate"],"sources":["../source/AsYouType.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport PhoneNumber from './PhoneNumber.js'\r\nimport AsYouTypeState from './AsYouTypeState.js'\r\nimport AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'\r\nimport AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'\r\nimport getCountryByCallingCode from './helpers/getCountryByCallingCode.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t/**\r\n\t * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.\r\n\t * @param {Object} metadata\r\n\t */\r\n\tconstructor(optionsOrDefaultCountry, metadata) {\r\n\t\tthis.metadata = new Metadata(metadata)\r\n\t\tconst [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\tgetCountryAndCallingCode(optionsOrDefaultCountry) {\r\n\t\t// Set `defaultCountry` and `defaultCallingCode` options.\r\n\t\tlet defaultCountry\r\n\t\tlet defaultCallingCode\r\n\t\t// Turns out `null` also has type \"object\". Weird.\r\n\t\tif (optionsOrDefaultCountry) {\r\n\t\t\tif (typeof optionsOrDefaultCountry === 'object') {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry.defaultCountry\r\n\t\t\t\tdefaultCallingCode = optionsOrDefaultCountry.defaultCallingCode\r\n\t\t\t} else {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {\r\n\t\t\tdefaultCountry = undefined\r\n\t\t}\r\n\t\tif (defaultCallingCode) {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {\r\n\t\t\t\t\tdefaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [defaultCountry, defaultCallingCode]\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number characters.\r\n\t * @param {string} text\r\n\t * @return {string} Formatted phone number characters that have been input so far.\r\n\t */\r\n\tinput(text) {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t} = this.parser.input(text, this.state)\r\n\t\tif (justLeadingPlus) {\r\n\t\t\tthis.formattedOutput = '+'\r\n\t\t} else if (digits) {\r\n\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tif (this.state.nationalSignificantNumber) {\r\n\t\t\t\tthis.formatter.narrowDownMatchingFormats(this.state)\r\n\t\t\t}\r\n\t\t\tlet formattedNationalNumber\r\n\t\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\t\tformattedNationalNumber = this.formatter.format(digits, this.state)\r\n\t\t\t}\r\n\t\t\tif (formattedNationalNumber === undefined) {\r\n\t\t\t\t// See if another national (significant) number could be re-extracted.\r\n\t\t\t\tif (this.parser.reExtractNationalSignificantNumber(this.state)) {\r\n\t\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\t\t// If it could, then re-try formatting the new national (significant) number.\r\n\t\t\t\t\tconst nationalDigits = this.state.getNationalDigits()\r\n\t\t\t\t\tif (nationalDigits) {\r\n\t\t\t\t\t\tformattedNationalNumber = this.formatter.format(nationalDigits, this.state)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.formattedOutput = formattedNationalNumber\r\n\t\t\t\t? this.getFullNumber(formattedNationalNumber)\r\n\t\t\t\t: this.getNonFormattedNumber()\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.state = new AsYouTypeState({\r\n\t\t\tonCountryChange: (country) => {\r\n\t\t\t\t// Before version `1.6.0`, the official `AsYouType` formatter API\r\n\t\t\t\t// included the `.country` property of an `AsYouType` instance.\r\n\t\t\t\t// Since that property (along with the others) have been moved to\r\n\t\t\t\t// `this.state`, `this.country` property is emulated for compatibility\r\n\t\t\t\t// with the old versions.\r\n\t\t\t\tthis.country = country\r\n\t\t\t},\r\n\t\t\tonCallingCodeChange: (callingCode, country) => {\r\n\t\t\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t\tthis.parser.reset(this.metadata.numberingPlan)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.formatter = new AsYouTypeFormatter({\r\n\t\t\tstate: this.state,\r\n\t\t\tmetadata: this.metadata\r\n\t\t})\r\n\t\tthis.parser = new AsYouTypeParser({\r\n\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\tdefaultCallingCode: this.defaultCallingCode,\r\n\t\t\tmetadata: this.metadata,\r\n\t\t\tstate: this.state,\r\n\t\t\tonNationalSignificantNumberChange: () => {\r\n\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.state.reset(this.defaultCountry, this.defaultCallingCode)\r\n\t\tthis.formattedOutput = ''\r\n\t\treturn this\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is being input in international format.\r\n\t * In other words, returns `true` if and only if the parsed phone number starts with a `\"+\"`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisInternational() {\r\n\t\treturn this.state.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"calling code\" part of the phone number when it's being input\r\n\t * in an international format.\r\n\t * If no valid calling code has been entered so far, returns `undefined`.\r\n\t * @return {string} [callingCode]\r\n\t */\r\n\tgetCallingCode() {\r\n\t\t // If the number is being input in national format and some \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then `this.state.callingCode`\r\n\t\t // is equal to that \"default calling code\".\r\n\t\t //\r\n\t\t // If the number is being input in national format and no \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then returns `undefined`,\r\n\t\t // even if a \"default country\" has been passed to `AsYouType` constructor.\r\n\t\t //\r\n\t\tif (this.isInternational()) {\r\n\t\t\treturn this.state.callingCode\r\n\t\t}\r\n\t}\r\n\r\n\t// A legacy alias.\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.getCallingCode()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * Returns `undefined` if no phone number has been input yet.\r\n\t * @return {string} [country]\r\n\t */\r\n\tgetCountry() {\r\n\t\tconst { digits } = this.state\r\n\t\t// Return `undefined` if no digits have been input yet.\r\n\t\tif (digits) {\r\n\t\t\treturn this._getCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * @return {string} [country]\r\n\t */\r\n\t_getCountry() {\r\n\t\tconst { country } = this.state\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t// `AsYouType.getCountry()` returns `undefined`\r\n\t\t\t// for \"non-geographic\" phone numbering plans.\r\n\t\t\tif (country === '001') {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn country\r\n\t}\r\n\r\n\tdetermineTheCountryIfNeeded() {\r\n\t\t// Suppose a user enters a phone number in international format,\r\n\t\t// and there're several countries corresponding to that country calling code,\r\n\t\t// and a country has been derived from the number, and then\r\n\t\t// a user enters one more digit and the number is no longer\r\n\t\t// valid for the derived country, so the country should be re-derived\r\n\t\t// on every new digit in those cases.\r\n\t\t//\r\n\t\t// If the phone number is being input in national format,\r\n\t\t// then it could be a case when `defaultCountry` wasn't specified\r\n\t\t// when creating `AsYouType` instance, and just `defaultCallingCode` was specified,\r\n\t\t// and that \"calling code\" could correspond to a \"non-geographic entity\",\r\n\t\t// or there could be several countries corresponding to that country calling code.\r\n\t\t// In those cases, `this.country` is `undefined` and should be derived\r\n\t\t// from the number. Again, if country calling code is ambiguous, then\r\n\t\t// `this.country` should be re-derived with each new digit.\r\n\t\t//\r\n\t\tif (!this.state.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\tthis.determineTheCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t// Prepends `+CountryCode ` in case of an international phone number\r\n\tgetFullNumber(formattedNationalNumber) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\tconst prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {\r\n\t\t\t\tspacing: text ? true : false\r\n\t\t\t}) + text\r\n\t\t\tconst { callingCode } = this.state\r\n\t\t\tif (!callingCode) {\r\n\t\t\t\treturn prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn prefix(callingCode)\r\n\t\t\t}\r\n\t\t\treturn prefix(`${callingCode} ${formattedNationalNumber}`)\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumberWithPrefix() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber,\r\n\t\t\tnationalPrefix\r\n\t\t} = this.state\r\n\t\tlet number = nationalSignificantNumber\r\n\t\tconst prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix\r\n\t\tif (prefix) {\r\n\t\t\tnumber = prefix + number\r\n\t\t}\r\n\t\treturn number\r\n\t}\r\n\r\n\tgetNonFormattedNumber() {\r\n\t\tconst { nationalSignificantNumberMatchesInput } = this.state\r\n\t\treturn this.getFullNumber(\r\n\t\t\tnationalSignificantNumberMatchesInput\r\n\t\t\t\t? this.getNonFormattedNationalNumberWithPrefix()\r\n\t\t\t\t: this.state.getNationalDigits()\r\n\t\t)\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\tconst number = this.getNonFormattedNumber()\r\n\t\tif (number) {\r\n\t\t\treturn number.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t\t}\r\n\t}\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst { callingCode } = this.state\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\t// Determines the country of the phone number\r\n\t// entered so far based on the country phone code\r\n\t// and the national phone number.\r\n\tdetermineTheCountry() {\r\n\t\tthis.state.setCountry(getCountryByCallingCode(\r\n\t\t\tthis.isInternational() ? this.state.callingCode : this.defaultCallingCode,\r\n\t\t\tthis.state.nationalSignificantNumber,\r\n\t\t\tthis.metadata\r\n\t\t))\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a E.164 phone number value for the user's input.\r\n\t *\r\n\t * For example, for country `\"US\"` and input `\"(222) 333-4444\"`\r\n\t * it will return `\"+12223334444\"`.\r\n\t *\r\n\t * For international phone number input, it will also auto-correct\r\n\t * some minor errors such as using a national prefix when writing\r\n\t * an international phone number. For example, if the user inputs\r\n\t * `\"+44 0 7400 000000\"` then it will return an auto-corrected\r\n\t * `\"+447400000000\"` phone number value.\r\n\t *\r\n\t * Will return `undefined` if no digits have been input,\r\n\t * or when inputting a phone number in national format and no\r\n\t * default country or default \"country calling code\" have been set.\r\n\t *\r\n\t * @return {string} [value]\r\n\t */\r\n\tgetNumberValue() {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tcallingCode,\r\n\t\t\tcountry,\r\n\t\t\tnationalSignificantNumber\r\n\t\t} = this.state\r\n\r\n\t \t// Will return `undefined` if no digits have been input.\r\n\t\tif (!digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (callingCode) {\r\n\t\t\t\treturn '+' + callingCode + nationalSignificantNumber\r\n\t\t\t} else {\r\n\t\t\t\treturn '+' + digits\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (country || callingCode) {\r\n\t\t\t\tconst callingCode_ = country ? this.metadata.countryCallingCode() : callingCode\r\n\t\t\t\treturn '+' + callingCode_ + nationalSignificantNumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an instance of `PhoneNumber` class.\r\n\t * Will return `undefined` if no national (significant) number\r\n\t * digits have been entered so far, or if no `defaultCountry` has been\r\n\t * set and the user enters a phone number not in international format.\r\n\t */\r\n\tgetNumber() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcarrierCode,\r\n\t\t\tcallingCode\r\n\t\t} = this.state\r\n\r\n\t\t// `this._getCountry()` is basically same as `this.state.country`\r\n\t\t// with the only change that it return `undefined` in case of a\r\n\t\t// \"non-geographic\" numbering plan instead of `\"001\"` \"internal use\" value.\r\n\t\tconst country = this._getCountry()\r\n\r\n\t\tif (!nationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (!country && !callingCode) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountry || callingCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (carrierCode) {\r\n\t\t\tphoneNumber.carrierCode = carrierCode\r\n\t\t}\r\n\t\t// Phone number extensions are not supported by \"As You Type\" formatter.\r\n\t\treturn phoneNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"possible\".\r\n\t * Is just a shortcut for `PhoneNumber.isPossible()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisPossible() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isPossible()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"valid\".\r\n\t * Is just a shortcut for `PhoneNumber.isValid()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisValid() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isValid()\r\n\t}\r\n\r\n\t/**\r\n\t * @deprecated\r\n\t * This method is used in `react-phone-number-input/source/input-control.js`\r\n\t * in versions before `3.0.16`.\r\n\t */\r\n\tgetNationalNumber() {\r\n\t\treturn this.state.nationalSignificantNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the phone number characters entered by the user.\r\n\t * @return {string}\r\n\t */\r\n\tgetChars() {\r\n\t\treturn (this.state.international ? '+' : '') + this.state.digits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the template for the formatted phone number.\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplate() {\r\n\t\treturn this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''\r\n\t}\r\n}"],"mappings":";;;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ACA;AACA;;;;WACC,sBAAa;MACZ,IAAMA,WAAW,GAAG,KAAKE,SAAL,EAApB;;MACA,IAAI,CAACF,WAAL,EAAkB;QACjB,OAAO,KAAP;MACA;;MACD,OAAOA,WAAW,CAACG,UAAZ,EAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,mBAAU;MACT,IAAMH,WAAW,GAAG,KAAKE,SAAL,EAApB;;MACA,IAAI,CAACF,WAAL,EAAkB;QACjB,OAAO,KAAP;MACA;;MACD,OAAOA,WAAW,CAACI,OAAZ,EAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,6BAAoB;MACnB,OAAO,KAAKvD,KAAL,CAAWK,yBAAlB;IACA;IAED;AACD;AACA;AACA;;;;WACC,oBAAW;MACV,OAAO,CAAC,KAAKL,KAAL,CAAW0B,aAAX,GAA2B,GAA3B,GAAiC,EAAlC,IAAwC,KAAK1B,KAAL,CAAWC,MAA1D;IACA;IAED;AACD;AACA;AACA;;;;WACC,uBAAc;MACb,OAAO,KAAKK,SAAL,CAAekD,WAAf,CAA2B,KAAKxD,KAAhC,KAA0C,KAAKyD,uBAAL,EAA1C,IAA4E,EAAnF;IACA"}
|
|
1
|
+
{"version":3,"file":"AsYouType.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","AsYouType","optionsOrDefaultCountry","metadata","Metadata","getCountryAndCallingCode","defaultCountry","defaultCallingCode","reset","hasCountry","undefined","isNonGeographicCallingCode","text","parser","input","state","digits","justLeadingPlus","formattedOutput","determineTheCountryIfNeeded","nationalSignificantNumber","formatter","narrowDownMatchingFormats","formattedNationalNumber","hasSelectedNumberingPlan","format","reExtractNationalSignificantNumber","nationalDigits","getNationalDigits","getFullNumber","getNonFormattedNumber","AsYouTypeState","onCountryChange","country","onCallingCodeChange","callingCode","selectNumberingPlan","numberingPlan","AsYouTypeFormatter","AsYouTypeParser","onNationalSignificantNumberChange","international","isInternational","getCallingCode","_getCountry","isCountryCallingCodeAmbiguous","determineTheCountry","prefix","getInternationalPrefixBeforeCountryCallingCode","spacing","getDigitsWithoutInternationalPrefix","complexPrefixBeforeNationalSignificantNumber","nationalPrefix","number","nationalSignificantNumberMatchesInput","getNonFormattedNationalNumberWithPrefix","replace","DIGIT_PLACEHOLDER","countryCodes","getCountryCodesForCallingCode","length","setCountry","getCountryByCallingCode","callingCode_","countryCallingCode","carrierCode","phoneNumber","PhoneNumber","getNumber","isPossible","isValid","getTemplate","getNonFormattedTemplate"],"sources":["../source/AsYouType.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport PhoneNumber from './PhoneNumber.js'\r\nimport AsYouTypeState from './AsYouTypeState.js'\r\nimport AsYouTypeFormatter, { DIGIT_PLACEHOLDER } from './AsYouTypeFormatter.js'\r\nimport AsYouTypeParser, { extractFormattedDigitsAndPlus } from './AsYouTypeParser.js'\r\nimport getCountryByCallingCode from './helpers/getCountryByCallingCode.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class AsYouType {\r\n\t/**\r\n\t * @param {(string|object)?} [optionsOrDefaultCountry] - The default country used for parsing non-international phone numbers. Can also be an `options` object.\r\n\t * @param {Object} metadata\r\n\t */\r\n\tconstructor(optionsOrDefaultCountry, metadata) {\r\n\t\tthis.metadata = new Metadata(metadata)\r\n\t\tconst [defaultCountry, defaultCallingCode] = this.getCountryAndCallingCode(optionsOrDefaultCountry)\r\n\t\tthis.defaultCountry = defaultCountry\r\n\t\tthis.defaultCallingCode = defaultCallingCode\r\n\t\tthis.reset()\r\n\t}\r\n\r\n\tgetCountryAndCallingCode(optionsOrDefaultCountry) {\r\n\t\t// Set `defaultCountry` and `defaultCallingCode` options.\r\n\t\tlet defaultCountry\r\n\t\tlet defaultCallingCode\r\n\t\t// Turns out `null` also has type \"object\". Weird.\r\n\t\tif (optionsOrDefaultCountry) {\r\n\t\t\tif (typeof optionsOrDefaultCountry === 'object') {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry.defaultCountry\r\n\t\t\t\tdefaultCallingCode = optionsOrDefaultCountry.defaultCallingCode\r\n\t\t\t} else {\r\n\t\t\t\tdefaultCountry = optionsOrDefaultCountry\r\n\t\t\t}\r\n\t\t}\r\n\t\tif (defaultCountry && !this.metadata.hasCountry(defaultCountry)) {\r\n\t\t\tdefaultCountry = undefined\r\n\t\t}\r\n\t\tif (defaultCallingCode) {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (this.metadata.isNonGeographicCallingCode(defaultCallingCode)) {\r\n\t\t\t\t\tdefaultCountry = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn [defaultCountry, defaultCallingCode]\r\n\t}\r\n\r\n\t/**\r\n\t * Inputs \"next\" phone number characters.\r\n\t * @param {string} text\r\n\t * @return {string} Formatted phone number characters that have been input so far.\r\n\t */\r\n\tinput(text) {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tjustLeadingPlus\r\n\t\t} = this.parser.input(text, this.state)\r\n\t\tif (justLeadingPlus) {\r\n\t\t\tthis.formattedOutput = '+'\r\n\t\t} else if (digits) {\r\n\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t// Match the available formats by the currently available leading digits.\r\n\t\t\tif (this.state.nationalSignificantNumber) {\r\n\t\t\t\tthis.formatter.narrowDownMatchingFormats(this.state)\r\n\t\t\t}\r\n\t\t\tlet formattedNationalNumber\r\n\t\t\tif (this.metadata.hasSelectedNumberingPlan()) {\r\n\t\t\t\tformattedNationalNumber = this.formatter.format(digits, this.state)\r\n\t\t\t}\r\n\t\t\tif (formattedNationalNumber === undefined) {\r\n\t\t\t\t// See if another national (significant) number could be re-extracted.\r\n\t\t\t\tif (this.parser.reExtractNationalSignificantNumber(this.state)) {\r\n\t\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\t\t// If it could, then re-try formatting the new national (significant) number.\r\n\t\t\t\t\tconst nationalDigits = this.state.getNationalDigits()\r\n\t\t\t\t\tif (nationalDigits) {\r\n\t\t\t\t\t\tformattedNationalNumber = this.formatter.format(nationalDigits, this.state)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tthis.formattedOutput = formattedNationalNumber\r\n\t\t\t\t? this.getFullNumber(formattedNationalNumber)\r\n\t\t\t\t: this.getNonFormattedNumber()\r\n\t\t}\r\n\t\treturn this.formattedOutput\r\n\t}\r\n\r\n\treset() {\r\n\t\tthis.state = new AsYouTypeState({\r\n\t\t\tonCountryChange: (country) => {\r\n\t\t\t\t// Before version `1.6.0`, the official `AsYouType` formatter API\r\n\t\t\t\t// included the `.country` property of an `AsYouType` instance.\r\n\t\t\t\t// Since that property (along with the others) have been moved to\r\n\t\t\t\t// `this.state`, `this.country` property is emulated for compatibility\r\n\t\t\t\t// with the old versions.\r\n\t\t\t\tthis.country = country\r\n\t\t\t},\r\n\t\t\tonCallingCodeChange: (callingCode, country) => {\r\n\t\t\t\tthis.metadata.selectNumberingPlan(country, callingCode)\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t\tthis.parser.reset(this.metadata.numberingPlan)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.formatter = new AsYouTypeFormatter({\r\n\t\t\tstate: this.state,\r\n\t\t\tmetadata: this.metadata\r\n\t\t})\r\n\t\tthis.parser = new AsYouTypeParser({\r\n\t\t\tdefaultCountry: this.defaultCountry,\r\n\t\t\tdefaultCallingCode: this.defaultCallingCode,\r\n\t\t\tmetadata: this.metadata,\r\n\t\t\tstate: this.state,\r\n\t\t\tonNationalSignificantNumberChange: () => {\r\n\t\t\t\tthis.determineTheCountryIfNeeded()\r\n\t\t\t\tthis.formatter.reset(this.metadata.numberingPlan, this.state)\r\n\t\t\t}\r\n\t\t})\r\n\t\tthis.state.reset({\r\n\t\t\tcountry: this.defaultCountry,\r\n\t\t\tcallingCode: this.defaultCallingCode\r\n\t\t})\r\n\t\tthis.formattedOutput = ''\r\n\t\treturn this\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is being input in international format.\r\n\t * In other words, returns `true` if and only if the parsed phone number starts with a `\"+\"`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisInternational() {\r\n\t\treturn this.state.international\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the \"calling code\" part of the phone number when it's being input\r\n\t * in an international format.\r\n\t * If no valid calling code has been entered so far, returns `undefined`.\r\n\t * @return {string} [callingCode]\r\n\t */\r\n\tgetCallingCode() {\r\n\t\t // If the number is being input in national format and some \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then `this.state.callingCode`\r\n\t\t // is equal to that \"default calling code\".\r\n\t\t //\r\n\t\t // If the number is being input in national format and no \"default calling code\"\r\n\t\t // has been passed to `AsYouType` constructor, then returns `undefined`,\r\n\t\t // even if a \"default country\" has been passed to `AsYouType` constructor.\r\n\t\t //\r\n\t\tif (this.isInternational()) {\r\n\t\t\treturn this.state.callingCode\r\n\t\t}\r\n\t}\r\n\r\n\t// A legacy alias.\r\n\tgetCountryCallingCode() {\r\n\t\treturn this.getCallingCode()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * Returns `undefined` if no phone number has been input yet.\r\n\t * @return {string} [country]\r\n\t */\r\n\tgetCountry() {\r\n\t\tconst { digits } = this.state\r\n\t\t// Return `undefined` if no digits have been input yet.\r\n\t\tif (digits) {\r\n\t\t\treturn this._getCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a two-letter country code of the phone number.\r\n\t * Returns `undefined` for \"non-geographic\" phone numbering plans.\r\n\t * @return {string} [country]\r\n\t */\r\n\t_getCountry() {\r\n\t\tconst { country } = this.state\r\n\t\t/* istanbul ignore if */\r\n\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t// `AsYouType.getCountry()` returns `undefined`\r\n\t\t\t// for \"non-geographic\" phone numbering plans.\r\n\t\t\tif (country === '001') {\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn country\r\n\t}\r\n\r\n\tdetermineTheCountryIfNeeded() {\r\n\t\t// Suppose a user enters a phone number in international format,\r\n\t\t// and there're several countries corresponding to that country calling code,\r\n\t\t// and a country has been derived from the number, and then\r\n\t\t// a user enters one more digit and the number is no longer\r\n\t\t// valid for the derived country, so the country should be re-derived\r\n\t\t// on every new digit in those cases.\r\n\t\t//\r\n\t\t// If the phone number is being input in national format,\r\n\t\t// then it could be a case when `defaultCountry` wasn't specified\r\n\t\t// when creating `AsYouType` instance, and just `defaultCallingCode` was specified,\r\n\t\t// and that \"calling code\" could correspond to a \"non-geographic entity\",\r\n\t\t// or there could be several countries corresponding to that country calling code.\r\n\t\t// In those cases, `this.country` is `undefined` and should be derived\r\n\t\t// from the number. Again, if country calling code is ambiguous, then\r\n\t\t// `this.country` should be re-derived with each new digit.\r\n\t\t//\r\n\t\tif (!this.state.country || this.isCountryCallingCodeAmbiguous()) {\r\n\t\t\tthis.determineTheCountry()\r\n\t\t}\r\n\t}\r\n\r\n\t// Prepends `+CountryCode ` in case of an international phone number\r\n\tgetFullNumber(formattedNationalNumber) {\r\n\t\tif (this.isInternational()) {\r\n\t\t\tconst prefix = (text) => this.formatter.getInternationalPrefixBeforeCountryCallingCode(this.state, {\r\n\t\t\t\tspacing: text ? true : false\r\n\t\t\t}) + text\r\n\t\t\tconst { callingCode } = this.state\r\n\t\t\tif (!callingCode) {\r\n\t\t\t\treturn prefix(`${this.state.getDigitsWithoutInternationalPrefix()}`)\r\n\t\t\t}\r\n\t\t\tif (!formattedNationalNumber) {\r\n\t\t\t\treturn prefix(callingCode)\r\n\t\t\t}\r\n\t\t\treturn prefix(`${callingCode} ${formattedNationalNumber}`)\r\n\t\t}\r\n\t\treturn formattedNationalNumber\r\n\t}\r\n\r\n\tgetNonFormattedNationalNumberWithPrefix() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcomplexPrefixBeforeNationalSignificantNumber,\r\n\t\t\tnationalPrefix\r\n\t\t} = this.state\r\n\t\tlet number = nationalSignificantNumber\r\n\t\tconst prefix = complexPrefixBeforeNationalSignificantNumber || nationalPrefix\r\n\t\tif (prefix) {\r\n\t\t\tnumber = prefix + number\r\n\t\t}\r\n\t\treturn number\r\n\t}\r\n\r\n\tgetNonFormattedNumber() {\r\n\t\tconst { nationalSignificantNumberMatchesInput } = this.state\r\n\t\treturn this.getFullNumber(\r\n\t\t\tnationalSignificantNumberMatchesInput\r\n\t\t\t\t? this.getNonFormattedNationalNumberWithPrefix()\r\n\t\t\t\t: this.state.getNationalDigits()\r\n\t\t)\r\n\t}\r\n\r\n\tgetNonFormattedTemplate() {\r\n\t\tconst number = this.getNonFormattedNumber()\r\n\t\tif (number) {\r\n\t\t\treturn number.replace(/[\\+\\d]/g, DIGIT_PLACEHOLDER)\r\n\t\t}\r\n\t}\r\n\r\n\tisCountryCallingCodeAmbiguous() {\r\n\t\tconst { callingCode } = this.state\r\n\t\tconst countryCodes = this.metadata.getCountryCodesForCallingCode(callingCode)\r\n\t\treturn countryCodes && countryCodes.length > 1\r\n\t}\r\n\r\n\t// Determines the country of the phone number\r\n\t// entered so far based on the country phone code\r\n\t// and the national phone number.\r\n\tdetermineTheCountry() {\r\n\t\tthis.state.setCountry(getCountryByCallingCode(\r\n\t\t\tthis.isInternational() ? this.state.callingCode : this.defaultCallingCode,\r\n\t\t\tthis.state.nationalSignificantNumber,\r\n\t\t\tthis.metadata\r\n\t\t))\r\n\t}\r\n\r\n\t/**\r\n\t * Returns a E.164 phone number value for the user's input.\r\n\t *\r\n\t * For example, for country `\"US\"` and input `\"(222) 333-4444\"`\r\n\t * it will return `\"+12223334444\"`.\r\n\t *\r\n\t * For international phone number input, it will also auto-correct\r\n\t * some minor errors such as using a national prefix when writing\r\n\t * an international phone number. For example, if the user inputs\r\n\t * `\"+44 0 7400 000000\"` then it will return an auto-corrected\r\n\t * `\"+447400000000\"` phone number value.\r\n\t *\r\n\t * Will return `undefined` if no digits have been input,\r\n\t * or when inputting a phone number in national format and no\r\n\t * default country or default \"country calling code\" have been set.\r\n\t *\r\n\t * @return {string} [value]\r\n\t */\r\n\tgetNumberValue() {\r\n\t\tconst {\r\n\t\t\tdigits,\r\n\t\t\tcallingCode,\r\n\t\t\tcountry,\r\n\t\t\tnationalSignificantNumber\r\n\t\t} = this.state\r\n\r\n\t \t// Will return `undefined` if no digits have been input.\r\n\t\tif (!digits) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (this.isInternational()) {\r\n\t\t\tif (callingCode) {\r\n\t\t\t\treturn '+' + callingCode + nationalSignificantNumber\r\n\t\t\t} else {\r\n\t\t\t\treturn '+' + digits\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tif (country || callingCode) {\r\n\t\t\t\tconst callingCode_ = country ? this.metadata.countryCallingCode() : callingCode\r\n\t\t\t\treturn '+' + callingCode_ + nationalSignificantNumber\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Returns an instance of `PhoneNumber` class.\r\n\t * Will return `undefined` if no national (significant) number\r\n\t * digits have been entered so far, or if no `defaultCountry` has been\r\n\t * set and the user enters a phone number not in international format.\r\n\t */\r\n\tgetNumber() {\r\n\t\tconst {\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tcarrierCode,\r\n\t\t\tcallingCode\r\n\t\t} = this.state\r\n\r\n\t\t// `this._getCountry()` is basically same as `this.state.country`\r\n\t\t// with the only change that it return `undefined` in case of a\r\n\t\t// \"non-geographic\" numbering plan instead of `\"001\"` \"internal use\" value.\r\n\t\tconst country = this._getCountry()\r\n\r\n\t\tif (!nationalSignificantNumber) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tif (!country && !callingCode) {\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\tconst phoneNumber = new PhoneNumber(\r\n\t\t\tcountry || callingCode,\r\n\t\t\tnationalSignificantNumber,\r\n\t\t\tthis.metadata.metadata\r\n\t\t)\r\n\t\tif (carrierCode) {\r\n\t\t\tphoneNumber.carrierCode = carrierCode\r\n\t\t}\r\n\t\t// Phone number extensions are not supported by \"As You Type\" formatter.\r\n\t\treturn phoneNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"possible\".\r\n\t * Is just a shortcut for `PhoneNumber.isPossible()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisPossible() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isPossible()\r\n\t}\r\n\r\n\t/**\r\n\t * Returns `true` if the phone number is \"valid\".\r\n\t * Is just a shortcut for `PhoneNumber.isValid()`.\r\n\t * @return {boolean}\r\n\t */\r\n\tisValid() {\r\n\t\tconst phoneNumber = this.getNumber()\r\n\t\tif (!phoneNumber) {\r\n\t\t\treturn false\r\n\t\t}\r\n\t\treturn phoneNumber.isValid()\r\n\t}\r\n\r\n\t/**\r\n\t * @deprecated\r\n\t * This method is used in `react-phone-number-input/source/input-control.js`\r\n\t * in versions before `3.0.16`.\r\n\t */\r\n\tgetNationalNumber() {\r\n\t\treturn this.state.nationalSignificantNumber\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the phone number characters entered by the user.\r\n\t * @return {string}\r\n\t */\r\n\tgetChars() {\r\n\t\treturn (this.state.international ? '+' : '') + this.state.digits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the template for the formatted phone number.\r\n\t * @return {string}\r\n\t */\r\n\tgetTemplate() {\r\n\t\treturn this.formatter.getTemplate(this.state) || this.getNonFormattedTemplate() || ''\r\n\t}\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,+BAA+B,GAA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AL,EAApB;;MACA,IAAI,CAACF,WAAL,EAAkB;QACjB,OAAO,KAAP;MACA;;MACD,OAAOA,WAAW,CAACG,UAAZ,EAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,mBAAU;MACT,IAAMH,WAAW,GAAG,KAAKE,SAAL,EAApB;;MACA,IAAI,CAACF,WAAL,EAAkB;QACjB,OAAO,KAAP;MACA;;MACD,OAAOA,WAAW,CAACI,OAAZ,EAAP;IACA;IAED;AACD;AACA;AACA;AACA;;;;WACC,6BAAoB;MACnB,OAAO,KAAKvD,KAAL,CAAWK,yBAAlB;IACA;IAED;AACD;AACA;AACA;;;;WACC,oBAAW;MACV,OAAO,CAAC,KAAKL,KAAL,CAAW0B,aAAX,GAA2B,GAA3B,GAAiC,EAAlC,IAAwC,KAAK1B,KAAL,CAAWC,MAA1D;IACA;IAED;AACD;AACA;AACA;;;;WACC,uBAAc;MACb,OAAO,KAAKK,SAAL,CAAekD,WAAf,CAA2B,KAAKxD,KAAhC,KAA0C,KAAKyD,uBAAL,EAA1C,IAA4E,EAAnF;IACA"}
|
package/build/AsYouTypeState.js
CHANGED
|
@@ -24,14 +24,16 @@ var AsYouTypeState = /*#__PURE__*/function () {
|
|
|
24
24
|
|
|
25
25
|
_createClass(AsYouTypeState, [{
|
|
26
26
|
key: "reset",
|
|
27
|
-
value: function reset(
|
|
27
|
+
value: function reset(_ref2) {
|
|
28
|
+
var country = _ref2.country,
|
|
29
|
+
callingCode = _ref2.callingCode;
|
|
28
30
|
this.international = false;
|
|
29
31
|
this.IDDPrefix = undefined;
|
|
30
32
|
this.missingPlus = undefined;
|
|
31
33
|
this.callingCode = undefined;
|
|
32
34
|
this.digits = '';
|
|
33
35
|
this.resetNationalSignificantNumber();
|
|
34
|
-
this.initCountryAndCallingCode(
|
|
36
|
+
this.initCountryAndCallingCode(country, callingCode);
|
|
35
37
|
}
|
|
36
38
|
}, {
|
|
37
39
|
key: "resetNationalSignificantNumber",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsYouTypeState.js","names":["AsYouTypeState","onCountryChange","onCallingCodeChange","
|
|
1
|
+
{"version":3,"file":"AsYouTypeState.js","names":["AsYouTypeState","onCountryChange","onCallingCodeChange","country","callingCode","international","IDDPrefix","undefined","missingPlus","digits","resetNationalSignificantNumber","initCountryAndCallingCode","nationalSignificantNumber","getNationalDigits","nationalSignificantNumberMatchesInput","nationalPrefix","carrierCode","complexPrefixBeforeNationalSignificantNumber","properties","Object","keys","key","setCountry","setCallingCode","nextDigits","slice","length"],"sources":["../source/AsYouTypeState.js"],"sourcesContent":["export default class AsYouTypeState {\r\n\tconstructor({ onCountryChange, onCallingCodeChange }) {\r\n\t\tthis.onCountryChange = onCountryChange\r\n\t\tthis.onCallingCodeChange = onCallingCodeChange\r\n\t}\r\n\r\n\treset({ country, callingCode }) {\r\n\t\tthis.international = false\r\n\t\tthis.IDDPrefix = undefined\r\n\t\tthis.missingPlus = undefined\r\n\t\tthis.callingCode = undefined\r\n\t\tthis.digits = ''\r\n\t\tthis.resetNationalSignificantNumber()\r\n\t\tthis.initCountryAndCallingCode(country, callingCode)\r\n\t}\r\n\r\n\tresetNationalSignificantNumber() {\r\n\t\tthis.nationalSignificantNumber = this.getNationalDigits()\r\n\t\tthis.nationalSignificantNumberMatchesInput = true\r\n\t\tthis.nationalPrefix = undefined\r\n\t\tthis.carrierCode = undefined\r\n\t\tthis.complexPrefixBeforeNationalSignificantNumber = undefined\r\n\t}\r\n\r\n\tupdate(properties) {\r\n\t\tfor (const key of Object.keys(properties)) {\r\n\t\t\tthis[key] = properties[key]\r\n\t\t}\r\n\t}\r\n\r\n\tinitCountryAndCallingCode(country, callingCode) {\r\n\t\tthis.setCountry(country)\r\n\t\tthis.setCallingCode(callingCode)\r\n\t}\r\n\r\n\tsetCountry(country) {\r\n\t\tthis.country = country\r\n\t\tthis.onCountryChange(country)\r\n\t}\r\n\r\n\tsetCallingCode(callingCode) {\r\n\t\tthis.callingCode = callingCode\r\n\t\tthis.onCallingCodeChange(callingCode, this.country)\r\n\t}\r\n\r\n\tstartInternationalNumber(country, callingCode) {\r\n\t\t// Prepend the `+` to parsed input.\r\n\t\tthis.international = true\r\n\t\t// If a default country was set then reset it\r\n\t\t// because an explicitly international phone\r\n\t\t// number is being entered.\r\n\t\tthis.initCountryAndCallingCode(country, callingCode)\r\n\t}\r\n\r\n\tappendDigits(nextDigits) {\r\n\t\tthis.digits += nextDigits\r\n\t}\r\n\r\n\tappendNationalSignificantNumberDigits(nextDigits) {\r\n\t\tthis.nationalSignificantNumber += nextDigits\r\n\t}\r\n\r\n\t/**\r\n\t * Returns the part of `this.digits` that corresponds to the national number.\r\n\t * Basically, all digits that have been input by the user, except for the\r\n\t * international prefix and the country calling code part\r\n\t * (if the number is an international one).\r\n\t * @return {string}\r\n\t */\r\n\tgetNationalDigits() {\r\n\t\tif (this.international) {\r\n\t\t\treturn this.digits.slice(\r\n\t\t\t\t(this.IDDPrefix ? this.IDDPrefix.length : 0) +\r\n\t\t\t\t(this.callingCode ? this.callingCode.length : 0)\r\n\t\t\t)\r\n\t\t}\r\n\t\treturn this.digits\r\n\t}\r\n\r\n\tgetDigitsWithoutInternationalPrefix() {\r\n\t\tif (this.international) {\r\n\t\t\tif (this.IDDPrefix) {\r\n\t\t\t\treturn this.digits.slice(this.IDDPrefix.length)\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn this.digits\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;IAAqBA,c;EACpB,8BAAsD;IAAA,IAAxCC,eAAwC,QAAxCA,eAAwC;IAAA,IAAvBC,mBAAuB,QAAvBA,mBAAuB;;IAAA;;IACrD,KAAKD,eAAL,GAAuBA,eAAvB;IACA,KAAKC,mBAAL,GAA2BA,mBAA3B;EACA;;;;WAED,sBAAgC;MAAA,IAAxBC,OAAwB,SAAxBA,OAAwB;MAAA,IAAfC,WAAe,SAAfA,WAAe;MAC/B,KAAKC,aAAL,GAAqB,KAArB;MACA,KAAKC,SA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ACA;IAED;AACD;AACA;AACA;AACA;AACA;AACA;;;;WACC,6BAAoB;MACnB,IAAI,KAAKnB,aAAT,EAAwB;QACvB,OAAO,KAAKI,MAAL,CAAYgB,KAAZ,CACN,CAAC,KAAKnB,SAAL,GAAiB,KAAKA,SAAL,CAAeoB,MAAhC,GAAyC,CAA1C,KACC,KAAKtB,WAAL,GAAmB,KAAKA,WAAL,CAAiBsB,MAApC,GAA6C,CAD9C,CADM,CAAP;MAIA;;MACD,OAAO,KAAKjB,MAAZ;IACA;;;WAED,+CAAsC;MACrC,IAAI,KAAKJ,aAAT,EAAwB;QACvB,IAAI,KAAKC,SAAT,EAAoB;UACnB,OAAO,KAAKG,MAAL,CAAYgB,KAAZ,CAAkB,KAAKnB,SAAL,CAAeoB,MAAjC,CAAP;QACA;MACD;;MACD,OAAO,KAAKjB,MAAZ;IACA"}
|
package/build/PhoneNumber.js
CHANGED
|
@@ -15,6 +15,8 @@ var _isValidNumberForRegion_ = _interopRequireDefault(require("./isValidNumberFo
|
|
|
15
15
|
|
|
16
16
|
var _getNumberType = _interopRequireDefault(require("./helpers/getNumberType.js"));
|
|
17
17
|
|
|
18
|
+
var _getPossibleCountriesForNumber = _interopRequireDefault(require("./helpers/getPossibleCountriesForNumber.js"));
|
|
19
|
+
|
|
18
20
|
var _format_ = _interopRequireDefault(require("./format_.js"));
|
|
19
21
|
|
|
20
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -79,6 +81,15 @@ var PhoneNumber = /*#__PURE__*/function () {
|
|
|
79
81
|
value: function setExt(ext) {
|
|
80
82
|
this.ext = ext;
|
|
81
83
|
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "getPossibleCountries",
|
|
86
|
+
value: function getPossibleCountries() {
|
|
87
|
+
if (this.country) {
|
|
88
|
+
return [this.country];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (0, _getPossibleCountriesForNumber["default"])(this.countryCallingCode, this.nationalNumber, this.metadata);
|
|
92
|
+
}
|
|
82
93
|
}, {
|
|
83
94
|
key: "isPossible",
|
|
84
95
|
value: function isPossible() {
|
package/build/PhoneNumber.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneNumber.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","PhoneNumber","countryCallingCode","nationalNumber","metadata","TypeError","_metadata","Metadata","isCountryCode","country","isNonGeographicCallingCode","number","ext","isPossibleNumber","v2","isValidNumber","phoneNumber","getNumberType","format","options","formatNumber","value","test"],"sources":["../source/PhoneNumber.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport isPossibleNumber from './isPossibleNumber_.js'\r\nimport isValidNumber from './validate_.js'\r\nimport isValidNumberForRegion from './isValidNumberForRegion_.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport formatNumber from './format_.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class PhoneNumber {\r\n\tconstructor(countryCallingCode, nationalNumber, metadata) {\r\n\t\tif (!countryCallingCode) {\r\n\t\t\tthrow new TypeError('`country` or `countryCallingCode` not passed')\r\n\t\t}\r\n\t\tif (!nationalNumber) {\r\n\t\t\tthrow new TypeError('`nationalNumber` not passed')\r\n\t\t}\r\n\t\tif (!metadata) {\r\n\t\t\tthrow new TypeError('`metadata` not passed')\r\n\t\t}\r\n\t\tconst _metadata = new Metadata(metadata)\r\n\t\t// If country code is passed then derive `countryCallingCode` from it.\r\n\t\t// Also store the country code as `.country`.\r\n\t\tif (isCountryCode(countryCallingCode)) {\r\n\t\t\tthis.country = countryCallingCode\r\n\t\t\t_metadata.country(countryCallingCode)\r\n\t\t\tcountryCallingCode = _metadata.countryCallingCode()\r\n\t\t} else {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (_metadata.isNonGeographicCallingCode(countryCallingCode)) {\r\n\t\t\t\t\tthis.country = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis.countryCallingCode = countryCallingCode\r\n\t\tthis.nationalNumber = nationalNumber\r\n\t\tthis.number = '+' + this.countryCallingCode + this.nationalNumber\r\n\t\tthis.metadata = metadata\r\n\t}\r\n\r\n\tsetExt(ext) {\r\n\t\tthis.ext = ext\r\n\t}\r\n\r\n\tisPossible() {\r\n\t\treturn isPossibleNumber(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tisValid() {\r\n\t\treturn isValidNumber(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tisNonGeographic() {\r\n\t\tconst metadata = new Metadata(this.metadata)\r\n\t\treturn metadata.isNonGeographicCallingCode(this.countryCallingCode)\r\n\t}\r\n\r\n\tisEqual(phoneNumber) {\r\n\t\treturn this.number === phoneNumber.number && this.ext === phoneNumber.ext\r\n\t}\r\n\r\n\t// // Is just an alias for `this.isValid() && this.country === country`.\r\n\t// // https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion\r\n\t// isValidForRegion(country) {\r\n\t// \treturn isValidNumberForRegion(this, country, { v2: true }, this.metadata)\r\n\t// }\r\n\r\n\tgetType() {\r\n\t\treturn getNumberType(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tformat(format, options) {\r\n\t\treturn formatNumber(\r\n\t\t\tthis,\r\n\t\t\tformat,\r\n\t\t\toptions ? { ...options, v2: true } : { v2: true },\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t}\r\n\r\n\tformatNational(options) {\r\n\t\treturn this.format('NATIONAL', options)\r\n\t}\r\n\r\n\tformatInternational(options) {\r\n\t\treturn this.format('INTERNATIONAL', options)\r\n\t}\r\n\r\n\tgetURI(options) {\r\n\t\treturn this.format('RFC3966', options)\r\n\t}\r\n}\r\n\r\nconst isCountryCode = (value) => /^[A-Z]{2}$/.test(value)"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;;IAEqBC,W;EACpB,qBAAYC,kBAAZ,EAAgCC,cAAhC,EAAgDC,QAAhD,EAA0D;IAAA;;IACzD,IAAI,CAACF,kBAAL,EAAyB;MACxB,MAAM,IAAIG,SAAJ,CAAc,8CAAd,CAAN;IACA;;IACD,IAAI,CAACF,cAAL,EAAqB;MACpB,MAAM,IAAIE,SAAJ,CAAc,6BAAd,CAAN;IACA;;IACD,IAAI,CAACD,QAAL,EAAe;MACd,MAAM,IAAIC,SAAJ,CAAc,uBAAd,CAAN;IACA;;IACD,IAAMC,SAAS,GAAG,IAAIC,qBAAJ,CAAaH,QAAb,CAAlB,CAVyD,CAWzD;IACA;;;IACA,IAAII,aAAa,CAACN,kBAAD,CAAjB,EAAuC;MACtC,KAAKO,OAAL,GAAeP,kBAAf;;MACAI,SAAS,CAACG,OAAV,CAAkBP,kBAAlB;;MACAA,kBAAkB,GAAGI,SAAS,CAACJ,kBAAV,EAArB;IACA,CAJD,MAIO;MACN;MACA,IAAIF,+BAAJ,EAAqC;QACpC,IAAIM,SAAS,CAACI,0BAAV,CAAqCR,kBAArC,CAAJ,EAA8D;UAC7D,KAAKO,OAAL,GAAe,KAAf;QACA;MACD;IACD;;IACD,KAAKP,kBAAL,GAA0BA,kBAA1B;IACA,KAAKC,cAAL,GAAsBA,cAAtB;IACA,KAAKQ,MAAL,GAAc,MAAM,KAAKT,kBAAX,GAAgC,KAAKC,cAAnD;IACA,KAAKC,QAAL,GAAgBA,QAAhB;EACA;;;;WAED,gBAAOQ,GAAP,EAAY;MACX,KAAKA,GAAL,GAAWA,GAAX;IACA;;;WAED,sBAAa;MACZ,OAAO,
|
|
1
|
+
{"version":3,"file":"PhoneNumber.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","PhoneNumber","countryCallingCode","nationalNumber","metadata","TypeError","_metadata","Metadata","isCountryCode","country","isNonGeographicCallingCode","number","ext","getPossibleCountriesForNumber","isPossibleNumber","v2","isValidNumber","phoneNumber","getNumberType","format","options","formatNumber","value","test"],"sources":["../source/PhoneNumber.js"],"sourcesContent":["import Metadata from './metadata.js'\r\nimport isPossibleNumber from './isPossibleNumber_.js'\r\nimport isValidNumber from './validate_.js'\r\nimport isValidNumberForRegion from './isValidNumberForRegion_.js'\r\nimport getNumberType from './helpers/getNumberType.js'\r\nimport getPossibleCountriesForNumber from './helpers/getPossibleCountriesForNumber.js'\r\nimport formatNumber from './format_.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default class PhoneNumber {\r\n\tconstructor(countryCallingCode, nationalNumber, metadata) {\r\n\t\tif (!countryCallingCode) {\r\n\t\t\tthrow new TypeError('`country` or `countryCallingCode` not passed')\r\n\t\t}\r\n\t\tif (!nationalNumber) {\r\n\t\t\tthrow new TypeError('`nationalNumber` not passed')\r\n\t\t}\r\n\t\tif (!metadata) {\r\n\t\t\tthrow new TypeError('`metadata` not passed')\r\n\t\t}\r\n\t\tconst _metadata = new Metadata(metadata)\r\n\t\t// If country code is passed then derive `countryCallingCode` from it.\r\n\t\t// Also store the country code as `.country`.\r\n\t\tif (isCountryCode(countryCallingCode)) {\r\n\t\t\tthis.country = countryCallingCode\r\n\t\t\t_metadata.country(countryCallingCode)\r\n\t\t\tcountryCallingCode = _metadata.countryCallingCode()\r\n\t\t} else {\r\n\t\t\t/* istanbul ignore if */\r\n\t\t\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\t\t\tif (_metadata.isNonGeographicCallingCode(countryCallingCode)) {\r\n\t\t\t\t\tthis.country = '001'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tthis.countryCallingCode = countryCallingCode\r\n\t\tthis.nationalNumber = nationalNumber\r\n\t\tthis.number = '+' + this.countryCallingCode + this.nationalNumber\r\n\t\tthis.metadata = metadata\r\n\t}\r\n\r\n\tsetExt(ext) {\r\n\t\tthis.ext = ext\r\n\t}\r\n\r\n\tgetPossibleCountries() {\r\n\t\tif (this.country) {\r\n\t\t\treturn [this.country]\r\n\t\t}\r\n\t\treturn getPossibleCountriesForNumber(\r\n\t\t\tthis.countryCallingCode,\r\n\t\t\tthis.nationalNumber,\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t}\r\n\r\n\tisPossible() {\r\n\t\treturn isPossibleNumber(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tisValid() {\r\n\t\treturn isValidNumber(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tisNonGeographic() {\r\n\t\tconst metadata = new Metadata(this.metadata)\r\n\t\treturn metadata.isNonGeographicCallingCode(this.countryCallingCode)\r\n\t}\r\n\r\n\tisEqual(phoneNumber) {\r\n\t\treturn this.number === phoneNumber.number && this.ext === phoneNumber.ext\r\n\t}\r\n\r\n\t// // Is just an alias for `this.isValid() && this.country === country`.\r\n\t// // https://github.com/googlei18n/libphonenumber/blob/master/FAQ.md#when-should-i-use-isvalidnumberforregion\r\n\t// isValidForRegion(country) {\r\n\t// \treturn isValidNumberForRegion(this, country, { v2: true }, this.metadata)\r\n\t// }\r\n\r\n\tgetType() {\r\n\t\treturn getNumberType(this, { v2: true }, this.metadata)\r\n\t}\r\n\r\n\tformat(format, options) {\r\n\t\treturn formatNumber(\r\n\t\t\tthis,\r\n\t\t\tformat,\r\n\t\t\toptions ? { ...options, v2: true } : { v2: true },\r\n\t\t\tthis.metadata\r\n\t\t)\r\n\t}\r\n\r\n\tformatNational(options) {\r\n\t\treturn this.format('NATIONAL', options)\r\n\t}\r\n\r\n\tformatInternational(options) {\r\n\t\treturn this.format('INTERNATIONAL', options)\r\n\t}\r\n\r\n\tgetURI(options) {\r\n\t\treturn this.format('RFC3966', options)\r\n\t}\r\n}\r\n\r\nconst isCountryCode = (value) => /^[A-Z]{2}$/.test(value)"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;A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IAAb,CAAkBD,KAAlB,CAAX;AAAA,CAAtB"}
|
|
@@ -48,5 +48,49 @@ describe('PhoneNumber', function () {
|
|
|
48
48
|
phoneNumber.ext.should.equal('1234');
|
|
49
49
|
phoneNumber.formatNational().should.equal('(213) 373-4253 ext. 1234');
|
|
50
50
|
});
|
|
51
|
+
it('should return possible countries', function () {
|
|
52
|
+
// "599": [
|
|
53
|
+
// "CW", // "possible_lengths": [7, 8]
|
|
54
|
+
// "BQ" // "possible_lengths": [7]
|
|
55
|
+
// ]
|
|
56
|
+
var phoneNumber = new _PhoneNumber["default"]('599', '123456', _metadataMin["default"]);
|
|
57
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
58
|
+
phoneNumber.getPossibleCountries().should.deep.equal([]);
|
|
59
|
+
phoneNumber = new _PhoneNumber["default"]('599', '1234567', _metadataMin["default"]);
|
|
60
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
61
|
+
phoneNumber.getPossibleCountries().should.deep.equal(['CW', 'BQ']);
|
|
62
|
+
phoneNumber = new _PhoneNumber["default"]('599', '12345678', _metadataMin["default"]);
|
|
63
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
64
|
+
phoneNumber.getPossibleCountries().should.deep.equal(['CW']);
|
|
65
|
+
phoneNumber = new _PhoneNumber["default"]('599', '123456789', _metadataMin["default"]);
|
|
66
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
67
|
+
phoneNumber.getPossibleCountries().should.deep.equal([]);
|
|
68
|
+
});
|
|
69
|
+
it('should return possible countries in case of ambiguity', function () {
|
|
70
|
+
var phoneNumber = new _PhoneNumber["default"]('1', '2223334444', _metadataMin["default"]);
|
|
71
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
72
|
+
phoneNumber.getPossibleCountries().indexOf('US').should.equal(0);
|
|
73
|
+
phoneNumber.getPossibleCountries().length.should.equal(25);
|
|
74
|
+
}); // it('should return empty possible countries when no national number has been input', () => {
|
|
75
|
+
// const phoneNumber = new PhoneNumber('1', '', metadata)
|
|
76
|
+
// expect(phoneNumber.country).to.be.undefined
|
|
77
|
+
// phoneNumber.getPossibleCountries().should.deep.equal([])
|
|
78
|
+
// })
|
|
79
|
+
|
|
80
|
+
it('should return empty possible countries when not enough national number digits have been input', function () {
|
|
81
|
+
var phoneNumber = new _PhoneNumber["default"]('1', '222', _metadataMin["default"]);
|
|
82
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
83
|
+
phoneNumber.getPossibleCountries().should.deep.equal([]);
|
|
84
|
+
});
|
|
85
|
+
it('should return possible countries in case of no ambiguity', function () {
|
|
86
|
+
var phoneNumber = new _PhoneNumber["default"]('US', '2133734253', _metadataMin["default"]);
|
|
87
|
+
phoneNumber.country.should.equal('US');
|
|
88
|
+
phoneNumber.getPossibleCountries().should.deep.equal(['US']);
|
|
89
|
+
});
|
|
90
|
+
it('should return empty possible countries in case of an unknown calling code', function () {
|
|
91
|
+
var phoneNumber = new _PhoneNumber["default"]('777', '123', _metadataMin["default"]);
|
|
92
|
+
expect(phoneNumber.country).to.be.undefined;
|
|
93
|
+
phoneNumber.getPossibleCountries().should.deep.equal([]);
|
|
94
|
+
});
|
|
51
95
|
});
|
|
52
96
|
//# sourceMappingURL=PhoneNumber.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneNumber.test.js","names":["describe","it","expect","PhoneNumber","to","phoneNumber","metadata","countryCallingCode","should","equal","country","number","ext","format","formatExtension","extension","isEqual","isNonGeographic","setExt","formatNational"],"sources":["../source/PhoneNumber.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' assert { type: 'json' }\r\nimport PhoneNumber from './PhoneNumber.js'\r\n\r\ndescribe('PhoneNumber', () => {\r\n\tit('should validate constructor arguments', () => {\r\n\t\texpect(() => new PhoneNumber()).to.throw('`countryCallingCode` not passed')\r\n\t\texpect(() => new PhoneNumber('7')).to.throw('`nationalNumber` not passed')\r\n\t\texpect(() => new PhoneNumber('7', '8005553535')).to.throw('`metadata` not passed')\r\n\t})\r\n\r\n\tit('should accept country code argument', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('RU', '8005553535', metadata)\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\t\tphoneNumber.number.should.equal('+78005553535')\r\n\t})\r\n\r\n\tit('should format number with options', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('7', '8005553535', metadata)\r\n\t\tphoneNumber.ext = '123'\r\n\t\tphoneNumber.format('NATIONAL', {\r\n\t\t\tformatExtension: (number, extension) => `${number} доб. ${extension}`\r\n\t\t})\r\n\t\t.should.equal('8 (800) 555-35-35 доб. 123')\r\n\t})\r\n\r\n\tit('should compare phone numbers', () => {\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('7', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553536', metadata)).should.equal(false)\r\n\t})\r\n\r\n\tit('should tell if a number is non-geographic', () => {\r\n\t\tnew PhoneNumber('7', '8005553535', metadata).isNonGeographic().should.equal(false)\r\n\t\tnew PhoneNumber('870', '773111632', metadata).isNonGeographic().should.equal(true)\r\n\t})\r\n\r\n\tit('should allow setting extension', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '2133734253', metadata)\r\n\t\tphoneNumber.setExt('1234')\r\n\t\tphoneNumber.ext.should.equal('1234')\r\n\t\tphoneNumber.formatNational().should.equal('(213) 373-4253 ext. 1234')\r\n\t})\r\n})"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;EAC7BC,EAAE,CAAC,uCAAD,EAA0C,YAAM;IACjDC,MAAM,CAAC;MAAA,OAAM,IAAIC,uBAAJ,EAAN;IAAA,CAAD,CAAN,CAAgCC,EAAhC,U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AA4GC,KAA5G,CAAkH,IAAlH;IACA,IAAIN,uBAAJ,CAAgB,IAAhB,EAAsB,YAAtB,EAAoCG,uBAApC,EAA8CU,OAA9C,CAAsD,IAAIb,uBAAJ,CAAgB,GAAhB,EAAqB,YAArB,EAAmCG,uBAAnC,CAAtD,EAAoGE,MAApG,CAA2GC,KAA3G,CAAiH,IAAjH;IACA,IAAIN,uBAAJ,CAAgB,IAAhB,EAAsB,YAAtB,EAAoCG,uBAApC,EAA8CU,OAA9C,CAAsD,IAAIb,uBAAJ,CAAgB,IAAhB,EAAsB,YAAtB,EAAoCG,uBAApC,CAAtD,EAAqGE,MAArG,CAA4GC,KAA5G,CAAkH,KAAlH;EACA,CAJC,CAAF;EAMAR,EAAE,CAAC,2CAAD,EAA8C,YAAM;IACrD,IAAIE,uBAAJ,CAAgB,GAAhB,EAAqB,YAArB,EAAmCG,uBAAnC,EAA6CW,eAA7C,GAA+DT,MAA/D,CAAsEC,KAAtE,CAA4E,KAA5E;IACA,IAAIN,uBAAJ,CAAgB,KAAhB,EAAuB,WAAvB,EAAoCG,uBAApC,EAA8CW,eAA9C,GAAgET,MAAhE,CAAuEC,KAAvE,CAA6E,IAA7E;EACA,CAHC,CAAF;EAKAR,EAAE,CAAC,gCAAD,EAAmC,YAAM;IAC1C,IAAMI,WAAW,GAAG,IAAIF,uBAAJ,CAAgB,GAAhB,EAAqB,YAArB,EAAmCG,uBAAnC,CAApB;IACAD,WAAW,CAACa,MAAZ,CAAmB,MAAnB;IACAb,WAAW,CAACO,GAAZ,CAAgBJ,MAAhB,CAAuBC,KAAvB,CAA6B,MAA7B;IACAJ,WAAW,CAACc,cAAZ,GAA6BX,MAA7B,CAAoCC,KAApC,CAA0C,0BAA1C;EACA,CALC,CAAF;
|
|
1
|
+
{"version":3,"file":"PhoneNumber.test.js","names":["describe","it","expect","PhoneNumber","to","phoneNumber","metadata","countryCallingCode","should","equal","country","number","ext","format","formatExtension","extension","isEqual","isNonGeographic","setExt","formatNational","be","undefined","getPossibleCountries","deep","indexOf","length"],"sources":["../source/PhoneNumber.test.js"],"sourcesContent":["import metadata from '../metadata.min.json' assert { type: 'json' }\r\nimport PhoneNumber from './PhoneNumber.js'\r\n\r\ndescribe('PhoneNumber', () => {\r\n\tit('should validate constructor arguments', () => {\r\n\t\texpect(() => new PhoneNumber()).to.throw('`countryCallingCode` not passed')\r\n\t\texpect(() => new PhoneNumber('7')).to.throw('`nationalNumber` not passed')\r\n\t\texpect(() => new PhoneNumber('7', '8005553535')).to.throw('`metadata` not passed')\r\n\t})\r\n\r\n\tit('should accept country code argument', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('RU', '8005553535', metadata)\r\n\t\tphoneNumber.countryCallingCode.should.equal('7')\r\n\t\tphoneNumber.country.should.equal('RU')\r\n\t\tphoneNumber.number.should.equal('+78005553535')\r\n\t})\r\n\r\n\tit('should format number with options', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('7', '8005553535', metadata)\r\n\t\tphoneNumber.ext = '123'\r\n\t\tphoneNumber.format('NATIONAL', {\r\n\t\t\tformatExtension: (number, extension) => `${number} доб. ${extension}`\r\n\t\t})\r\n\t\t.should.equal('8 (800) 555-35-35 доб. 123')\r\n\t})\r\n\r\n\tit('should compare phone numbers', () => {\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('7', '8005553535', metadata)).should.equal(true)\r\n\t\tnew PhoneNumber('RU', '8005553535', metadata).isEqual(new PhoneNumber('RU', '8005553536', metadata)).should.equal(false)\r\n\t})\r\n\r\n\tit('should tell if a number is non-geographic', () => {\r\n\t\tnew PhoneNumber('7', '8005553535', metadata).isNonGeographic().should.equal(false)\r\n\t\tnew PhoneNumber('870', '773111632', metadata).isNonGeographic().should.equal(true)\r\n\t})\r\n\r\n\tit('should allow setting extension', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '2133734253', metadata)\r\n\t\tphoneNumber.setExt('1234')\r\n\t\tphoneNumber.ext.should.equal('1234')\r\n\t\tphoneNumber.formatNational().should.equal('(213) 373-4253 ext. 1234')\r\n\t})\r\n\r\n\tit('should return possible countries', () => {\r\n // \"599\": [\r\n // \"CW\", // \"possible_lengths\": [7, 8]\r\n // \"BQ\" // \"possible_lengths\": [7]\r\n // ]\r\n\r\n\t\tlet phoneNumber = new PhoneNumber('599', '123456', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\r\n\t\tphoneNumber = new PhoneNumber('599', '1234567', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal(['CW', 'BQ'])\r\n\r\n\t\tphoneNumber = new PhoneNumber('599', '12345678', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal(['CW'])\r\n\r\n\t\tphoneNumber = new PhoneNumber('599', '123456789', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t})\r\n\r\n\tit('should return possible countries in case of ambiguity', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '2223334444', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().indexOf('US').should.equal(0)\r\n\t\tphoneNumber.getPossibleCountries().length.should.equal(25)\r\n\t})\r\n\r\n\t// it('should return empty possible countries when no national number has been input', () => {\r\n\t// \tconst phoneNumber = new PhoneNumber('1', '', metadata)\r\n\t// \texpect(phoneNumber.country).to.be.undefined\r\n\t// \tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t// })\r\n\r\n\tit('should return empty possible countries when not enough national number digits have been input', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('1', '222', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t})\r\n\r\n\tit('should return possible countries in case of no ambiguity', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('US', '2133734253', metadata)\r\n\t\tphoneNumber.country.should.equal('US')\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal(['US'])\r\n\t})\r\n\r\n\tit('should return empty possible countries in case of an unknown calling code', () => {\r\n\t\tconst phoneNumber = new PhoneNumber('777', '123', metadata)\r\n\t\texpect(phoneNumber.country).to.be.undefined\r\n\t\tphoneNumber.getPossibleCountries().should.deep.equal([])\r\n\t})\r\n})"],"mappings":";;AAAA;;AACA;;;;AAEAA,QAAQ,CAAC,aAAD,EAAgB,YAAM;EAC7BC,EAAE,CAAC,uCAAD,EAA0C,YAAM;IACjDC,MAAM,CAAC;MAAA,OAAM,IAAIC,uBAAJ,EAAN;IAAA,CAAD,CAAN,CAAgCC,EAAhC,UAAyC,iCAAzC;IACAF,MAAM,CAAC;MAAA,OAAM,IAAIC,uBAAJ,CAAgB,GAAhB,CAAN;IAAA,CAAD,CAAN,CAAmCC,EAAnC,UAA4C,6BAA5C;IACAF,MAAM,CAAC;MAAA,OAAM,IAAIC,uBAAJ,CAAgB,GAAhB,EAAqB,YAArB,CAAN;IAAA,CAAD,CAAN,CAAiDC,EAAjD,UAA0D,uBAA1D;EACA,CAJC,CAAF;EAMAH,EAAE,CAAC,qCAAD,EAAwC,YAAM;IAC/C,IAAMI,WAAW,GAAG,IAAIF,uBAAJ,CAAgB,IAAhB,EAAsB,YAAtB,EAAoCG,uBAApC,CAApB;IACAD,WAAW,CAACE,kBAAZ,CAA+BC,MAA/B,CAAsCC,KAAtC,CAA4C,GAA5C;IACAJ,WAAW,CAACK,OAAZ,CAAoBF,MAApB,CAA2BC,KAA3B,CAAiC,IAAjC;IACAJ,WAAW,CAACM,MAAZ,CAAmBH,MAAnB,CAA0BC,KAA1B,CAAgC,cAAhC;EACA,CALC,CAAF;EAOAR,EAAE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AD,EAA6D,YAAM;IACpE,IAAMI,WAAW,GAAG,IAAIF,uBAAJ,CAAgB,IAAhB,EAAsB,YAAtB,EAAoCG,uBAApC,CAApB;IACAD,WAAW,CAACK,OAAZ,CAAoBF,MAApB,CAA2BC,KAA3B,CAAiC,IAAjC;IACAJ,WAAW,CAACiB,oBAAZ,GAAmCd,MAAnC,CAA0Ce,IAA1C,CAA+Cd,KAA/C,CAAqD,CAAC,IAAD,CAArD;EACA,CAJC,CAAF;EAMAR,EAAE,CAAC,2EAAD,EAA8E,YAAM;IACrF,IAAMI,WAAW,GAAG,IAAIF,uBAAJ,CAAgB,KAAhB,EAAuB,KAAvB,EAA8BG,uBAA9B,CAApB;IACAJ,MAAM,CAACG,WAAW,CAACK,OAAb,CAAN,CAA4BN,EAA5B,CAA+BgB,EAA/B,CAAkCC,SAAlC;IACAhB,WAAW,CAACiB,oBAAZ,GAAmCd,MAAnC,CAA0Ce,IAA1C,CAA+Cd,KAA/C,CAAqD,EAArD;EACA,CAJC,CAAF;AAKA,CA9FO,CAAR"}
|
|
@@ -5,18 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = getCountryByCallingCode;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _getNumberType = _interopRequireDefault(require("./getNumberType.js"));
|
|
8
|
+
var _getCountryByNationalNumber = _interopRequireDefault(require("./getCountryByNationalNumber.js"));
|
|
11
9
|
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
11
|
|
|
14
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
-
|
|
16
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
-
|
|
18
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
19
|
-
|
|
20
12
|
var USE_NON_GEOGRAPHIC_COUNTRY_CODE = false;
|
|
21
13
|
|
|
22
14
|
function getCountryByCallingCode(callingCode, nationalPhoneNumber, metadata) {
|
|
@@ -25,8 +17,7 @@ function getCountryByCallingCode(callingCode, nationalPhoneNumber, metadata) {
|
|
|
25
17
|
if (metadata.isNonGeographicCallingCode(callingCode)) {
|
|
26
18
|
return '001';
|
|
27
19
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
20
|
+
}
|
|
30
21
|
|
|
31
22
|
var possibleCountries = metadata.getCountryCodesForCallingCode(callingCode);
|
|
32
23
|
|
|
@@ -40,32 +31,6 @@ function getCountryByCallingCode(callingCode, nationalPhoneNumber, metadata) {
|
|
|
40
31
|
return possibleCountries[0];
|
|
41
32
|
}
|
|
42
33
|
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function selectCountryFromList(possibleCountries, nationalPhoneNumber, metadata) {
|
|
47
|
-
// Re-create `metadata` because it will be selecting a `country`.
|
|
48
|
-
metadata = new _metadata["default"](metadata);
|
|
49
|
-
|
|
50
|
-
for (var _iterator = _createForOfIteratorHelperLoose(possibleCountries), _step; !(_step = _iterator()).done;) {
|
|
51
|
-
var country = _step.value;
|
|
52
|
-
metadata.country(country); // Leading digits check would be the simplest and fastest one.
|
|
53
|
-
// Leading digits patterns are only defined for about 20% of all countries.
|
|
54
|
-
// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits
|
|
55
|
-
// Matching "leading digits" is a sufficient but not necessary condition.
|
|
56
|
-
|
|
57
|
-
if (metadata.leadingDigits()) {
|
|
58
|
-
if (nationalPhoneNumber && nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
|
|
59
|
-
return country;
|
|
60
|
-
}
|
|
61
|
-
} // Else perform full validation with all of those
|
|
62
|
-
// fixed-line/mobile/etc regular expressions.
|
|
63
|
-
else if ((0, _getNumberType["default"])({
|
|
64
|
-
phone: nationalPhoneNumber,
|
|
65
|
-
country: country
|
|
66
|
-
}, undefined, metadata.metadata)) {
|
|
67
|
-
return country;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
34
|
+
return (0, _getCountryByNationalNumber["default"])(possibleCountries, nationalPhoneNumber, metadata.metadata);
|
|
70
35
|
}
|
|
71
36
|
//# sourceMappingURL=getCountryByCallingCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCountryByCallingCode.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","nationalPhoneNumber","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length","
|
|
1
|
+
{"version":3,"file":"getCountryByCallingCode.js","names":["USE_NON_GEOGRAPHIC_COUNTRY_CODE","getCountryByCallingCode","callingCode","nationalPhoneNumber","metadata","isNonGeographicCallingCode","possibleCountries","getCountryCodesForCallingCode","length","getCountryByNationalNumber"],"sources":["../../source/helpers/getCountryByCallingCode.js"],"sourcesContent":["import getCountryByNationalNumber from './getCountryByNationalNumber.js'\r\n\r\nconst USE_NON_GEOGRAPHIC_COUNTRY_CODE = false\r\n\r\nexport default function getCountryByCallingCode(callingCode, nationalPhoneNumber, metadata) {\r\n\t/* istanbul ignore if */\r\n\tif (USE_NON_GEOGRAPHIC_COUNTRY_CODE) {\r\n\t\tif (metadata.isNonGeographicCallingCode(callingCode)) {\r\n\t\t\treturn '001'\r\n\t\t}\r\n\t}\r\n\tconst possibleCountries = metadata.getCountryCodesForCallingCode(callingCode)\r\n\tif (!possibleCountries) {\r\n\t\treturn\r\n\t}\r\n\t// If there's just one country corresponding to the country code,\r\n\t// then just return it, without further phone number digits validation.\r\n\tif (possibleCountries.length === 1) {\r\n\t\treturn possibleCountries[0]\r\n\t}\r\n\treturn getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata.metadata)\r\n}"],"mappings":";;;;;;;AAAA;;;;AAEA,IAAMA,+BAA+B,GAAG,KAAxC;;AAEe,SAASC,uBAAT,CAAiCC,WAAjC,EAA8CC,mBAA9C,EAAmEC,QAAnE,EAA6E;EAC3F;EACA,IAAIJ,+BAAJ,EAAqC;IACpC,IAAII,QAAQ,CAACC,0BAAT,CAAoCH,WAApC,CAAJ,EAAsD;MACrD,OAAO,KAAP;IACA;EACD;;EACD,IAAMI,iBAAiB,GAAGF,QAAQ,CAACG,6BAAT,CAAuCL,WAAvC,CAA1B;;EACA,IAAI,CAACI,iBAAL,EAAwB;IACvB;EACA,CAV0F,CAW3F;EACA;;;EACA,IAAIA,iBAAiB,CAACE,MAAlB,KAA6B,CAAjC,EAAoC;IACnC,OAAOF,iBAAiB,CAAC,CAAD,CAAxB;EACA;;EACD,OAAO,IAAAG,sCAAA,EAA2BH,iBAA3B,EAA8CH,mBAA9C,EAAmEC,QAAQ,CAACA,QAA5E,CAAP;AACA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = getCountryByNationalNumber;
|
|
7
|
+
|
|
8
|
+
var _metadata = _interopRequireDefault(require("../metadata.js"));
|
|
9
|
+
|
|
10
|
+
var _getNumberType = _interopRequireDefault(require("./getNumberType.js"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
19
|
+
|
|
20
|
+
function getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata) {
|
|
21
|
+
// Re-create `metadata` because it will be selecting a `country`.
|
|
22
|
+
metadata = new _metadata["default"](metadata);
|
|
23
|
+
|
|
24
|
+
for (var _iterator = _createForOfIteratorHelperLoose(possibleCountries), _step; !(_step = _iterator()).done;) {
|
|
25
|
+
var country = _step.value;
|
|
26
|
+
metadata.country(country); // "Leading digits" patterns are only defined for about 20% of all countries.
|
|
27
|
+
// By definition, matching "leading digits" is a sufficient but not a necessary
|
|
28
|
+
// condition for a phone number to belong to a country.
|
|
29
|
+
// The point of "leading digits" check is that it's the fastest one to get a match.
|
|
30
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits
|
|
31
|
+
|
|
32
|
+
if (metadata.leadingDigits()) {
|
|
33
|
+
if (nationalPhoneNumber && nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
|
|
34
|
+
return country;
|
|
35
|
+
}
|
|
36
|
+
} // Else perform full validation with all of those
|
|
37
|
+
// fixed-line/mobile/etc regular expressions.
|
|
38
|
+
else if ((0, _getNumberType["default"])({
|
|
39
|
+
phone: nationalPhoneNumber,
|
|
40
|
+
country: country
|
|
41
|
+
}, undefined, metadata.metadata)) {
|
|
42
|
+
return country;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=getCountryByNationalNumber.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCountryByNationalNumber.js","names":["getCountryByNationalNumber","possibleCountries","nationalPhoneNumber","metadata","Metadata","country","leadingDigits","search","getNumberType","phone","undefined"],"sources":["../../source/helpers/getCountryByNationalNumber.js"],"sourcesContent":["import Metadata from '../metadata.js'\r\nimport getNumberType from './getNumberType.js'\r\n\r\nexport default function getCountryByNationalNumber(possibleCountries, nationalPhoneNumber, metadata) {\r\n\t// Re-create `metadata` because it will be selecting a `country`.\r\n\tmetadata = new Metadata(metadata)\r\n\tfor (const country of possibleCountries) {\r\n\t\tmetadata.country(country)\r\n\t\t// \"Leading digits\" patterns are only defined for about 20% of all countries.\r\n\t\t// By definition, matching \"leading digits\" is a sufficient but not a necessary\r\n\t\t// condition for a phone number to belong to a country.\r\n\t\t// The point of \"leading digits\" check is that it's the fastest one to get a match.\r\n\t\t// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits\r\n\t\tif (metadata.leadingDigits()) {\r\n\t\t\tif (nationalPhoneNumber &&\r\n\t\t\t\tnationalPhoneNumber.search(metadata.leadingDigits()) === 0) {\r\n\t\t\t\treturn country\r\n\t\t\t}\r\n\t\t}\r\n\t\t// Else perform full validation with all of those\r\n\t\t// fixed-line/mobile/etc regular expressions.\r\n\t\telse if (getNumberType({ phone: nationalPhoneNumber, country }, undefined, metadata.metadata)) {\r\n\t\t\treturn country\r\n\t\t}\r\n\t}\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;;;;;;;;;AAEe,SAASA,0BAAT,CAAoCC,iBAApC,EAAuDC,mBAAvD,EAA4EC,QAA5E,EAAsF;EACpG;EACAA,QAAQ,GAAG,IAAIC,oBAAJ,CAAaD,QAAb,CAAX;;EACA,qDAAsBF,iBAAtB,wCAAyC;IAAA,IAA9BI,OAA8B;IACxCF,QAAQ,CAACE,OAAT,CAAiBA,OAAjB,EADwC,CAExC;IACA;IACA;IACA;IACA;;IACA,IAAIF,QAAQ,CAACG,aAAT,EAAJ,EAA8B;MAC7B,IAAIJ,mBAAmB,IACtBA,mBAAmB,CAACK,MAApB,CAA2BJ,QAAQ,CAACG,aAAT,EAA3B,MAAyD,CAD1D,EAC6D;QAC5D,OAAOD,OAAP;MACA;IACD,CALD,CAMA;IACA;IAPA,KAQK,IAAI,IAAAG,yBAAA,EAAc;MAAEC,KAAK,EAAEP,mBAAT;MAA8BG,OAAO,EAAPA;IAA9B,CAAd,EAAuDK,SAAvD,EAAkEP,QAAQ,CAACA,QAA3E,CAAJ,EAA0F;MAC9F,OAAOE,OAAP;IACA;EACD;AACD"}
|