ingeniuscliq-core 0.5.36 → 0.5.38
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/dist/components/common/form/FormPhone.d.ts +4 -1
- package/dist/components/common/form/FormPhone.d.ts.map +1 -1
- package/dist/components/common/form/FormPhone.js +35 -5
- package/dist/node_modules/libphonenumber-js/es6/ParseError.js +34 -0
- package/dist/node_modules/libphonenumber-js/es6/PhoneNumber.js +194 -0
- package/dist/node_modules/libphonenumber-js/es6/constants.js +32 -0
- package/dist/node_modules/libphonenumber-js/es6/format.js +208 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/RFC3966.js +17 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/applyInternationalSeparatorStyle.js +37 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/checkNumberLength.js +82 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extension/createExtensionPattern.js +96 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extension/extractExtension.js +31 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractCountryCallingCode.js +142 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractCountryCallingCodeFromInternationalNumberWithoutPlusSign.js +47 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractFormattedPhoneNumberFromPossibleRfc3966NumberUri.js +66 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractNationalNumber.js +117 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractNationalNumberFromPossiblyIncompleteNumber.js +103 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/extractPhoneContext.js +82 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/formatNationalNumberUsingFormat.js +32 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryByCallingCode.js +23 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getCountryByNationalNumber.js +81 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getIddPrefix.js +27 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getNumberType.js +86 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/getPossibleCountriesForNumber.js +29 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/isViablePhoneNumber.js +78 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/matchesEntirely.js +13 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/parseDigits.js +82 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/stripIddPrefix.js +31 -0
- package/dist/node_modules/libphonenumber-js/es6/isPossible.js +78 -0
- package/dist/node_modules/libphonenumber-js/es6/isValid.js +58 -0
- package/dist/node_modules/libphonenumber-js/es6/isValidPhoneNumber.js +22 -0
- package/dist/node_modules/libphonenumber-js/es6/metadata.js +6 -1
- package/dist/node_modules/libphonenumber-js/es6/normalizeArguments.js +70 -0
- package/dist/node_modules/libphonenumber-js/es6/parse.js +326 -0
- package/dist/node_modules/libphonenumber-js/es6/parseIncompletePhoneNumber.js +62 -0
- package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumberWithError_.js +15 -0
- package/dist/node_modules/libphonenumber-js/es6/parsePhoneNumber_.js +29 -0
- package/dist/node_modules/libphonenumber-js/min/exports/isValidPhoneNumber.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strips any national prefix (such as 0, 1) present in a
|
|
3
|
+
* (possibly incomplete) number provided.
|
|
4
|
+
* "Carrier codes" are only used in Colombia and Brazil,
|
|
5
|
+
* and only when dialing within those countries from a mobile phone to a fixed line number.
|
|
6
|
+
* Sometimes it won't actually strip national prefix
|
|
7
|
+
* and will instead prepend some digits to the `number`:
|
|
8
|
+
* for example, when number `2345678` is passed with `VI` country selected,
|
|
9
|
+
* it will return `{ number: "3402345678" }`, because `340` area code is prepended.
|
|
10
|
+
* @param {string} number — National number digits.
|
|
11
|
+
* @param {object} metadata — Metadata with country selected.
|
|
12
|
+
* @return {object} `{ nationalNumber: string, nationalPrefix: string? carrierCode: string? }`. Even if a national prefix was extracted, it's not necessarily present in the returned object, so don't rely on its presence in the returned object in order to find out whether a national prefix has been extracted or not.
|
|
13
|
+
*/
|
|
14
|
+
function extractNationalNumberFromPossiblyIncompleteNumber(number, metadata) {
|
|
15
|
+
if (number && metadata.numberingPlan.nationalPrefixForParsing()) {
|
|
16
|
+
// See METADATA.md for the description of
|
|
17
|
+
// `national_prefix_for_parsing` and `national_prefix_transform_rule`.
|
|
18
|
+
// Attempt to parse the first digits as a national prefix.
|
|
19
|
+
var prefixPattern = new RegExp('^(?:' + metadata.numberingPlan.nationalPrefixForParsing() + ')');
|
|
20
|
+
var prefixMatch = prefixPattern.exec(number);
|
|
21
|
+
if (prefixMatch) {
|
|
22
|
+
var nationalNumber;
|
|
23
|
+
var carrierCode;
|
|
24
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/-/blob/master/METADATA.md#national_prefix_for_parsing--national_prefix_transform_rule
|
|
25
|
+
// If a `national_prefix_for_parsing` has any "capturing groups"
|
|
26
|
+
// then it means that the national (significant) number is equal to
|
|
27
|
+
// those "capturing groups" transformed via `national_prefix_transform_rule`,
|
|
28
|
+
// and nothing could be said about the actual national prefix:
|
|
29
|
+
// what is it and was it even there.
|
|
30
|
+
// If a `national_prefix_for_parsing` doesn't have any "capturing groups",
|
|
31
|
+
// then everything it matches is a national prefix.
|
|
32
|
+
// To determine whether `national_prefix_for_parsing` matched any
|
|
33
|
+
// "capturing groups", the value of the result of calling `.exec()`
|
|
34
|
+
// is looked at, and if it has non-undefined values where there're
|
|
35
|
+
// "capturing groups" in the regular expression, then it means
|
|
36
|
+
// that "capturing groups" have been matched.
|
|
37
|
+
// It's not possible to tell whether there'll be any "capturing gropus"
|
|
38
|
+
// before the matching process, because a `national_prefix_for_parsing`
|
|
39
|
+
// could exhibit both behaviors.
|
|
40
|
+
var capturedGroupsCount = prefixMatch.length - 1;
|
|
41
|
+
var hasCapturedGroups = capturedGroupsCount > 0 && prefixMatch[capturedGroupsCount];
|
|
42
|
+
if (metadata.nationalPrefixTransformRule() && hasCapturedGroups) {
|
|
43
|
+
nationalNumber = number.replace(prefixPattern, metadata.nationalPrefixTransformRule());
|
|
44
|
+
// If there's more than one captured group,
|
|
45
|
+
// then carrier code is the second one.
|
|
46
|
+
if (capturedGroupsCount > 1) {
|
|
47
|
+
carrierCode = prefixMatch[1];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// If there're no "capturing groups",
|
|
51
|
+
// or if there're "capturing groups" but no
|
|
52
|
+
// `national_prefix_transform_rule`,
|
|
53
|
+
// then just strip the national prefix from the number,
|
|
54
|
+
// and possibly a carrier code.
|
|
55
|
+
// Seems like there could be more.
|
|
56
|
+
else {
|
|
57
|
+
// `prefixBeforeNationalNumber` is the whole substring matched by
|
|
58
|
+
// the `national_prefix_for_parsing` regular expression.
|
|
59
|
+
// There seem to be no guarantees that it's just a national prefix.
|
|
60
|
+
// For example, if there's a carrier code, it's gonna be a
|
|
61
|
+
// part of `prefixBeforeNationalNumber` too.
|
|
62
|
+
var prefixBeforeNationalNumber = prefixMatch[0];
|
|
63
|
+
nationalNumber = number.slice(prefixBeforeNationalNumber.length);
|
|
64
|
+
// If there's at least one captured group,
|
|
65
|
+
// then carrier code is the first one.
|
|
66
|
+
if (hasCapturedGroups) {
|
|
67
|
+
carrierCode = prefixMatch[1];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Tries to guess whether a national prefix was present in the input.
|
|
71
|
+
// This is not something copy-pasted from Google's library:
|
|
72
|
+
// they don't seem to have an equivalent for that.
|
|
73
|
+
// So this isn't an "officially approved" way of doing something like that.
|
|
74
|
+
// But since there seems no other existing method, this library uses it.
|
|
75
|
+
var nationalPrefix;
|
|
76
|
+
if (hasCapturedGroups) {
|
|
77
|
+
var possiblePositionOfTheFirstCapturedGroup = number.indexOf(prefixMatch[1]);
|
|
78
|
+
var possibleNationalPrefix = number.slice(0, possiblePositionOfTheFirstCapturedGroup);
|
|
79
|
+
// Example: an Argentinian (AR) phone number `0111523456789`.
|
|
80
|
+
// `prefixMatch[0]` is `01115`, and `$1` is `11`,
|
|
81
|
+
// and the rest of the phone number is `23456789`.
|
|
82
|
+
// The national number is transformed via `9$1` to `91123456789`.
|
|
83
|
+
// National prefix `0` is detected being present at the start.
|
|
84
|
+
// if (possibleNationalPrefix.indexOf(metadata.numberingPlan.nationalPrefix()) === 0) {
|
|
85
|
+
if (possibleNationalPrefix === metadata.numberingPlan.nationalPrefix()) {
|
|
86
|
+
nationalPrefix = metadata.numberingPlan.nationalPrefix();
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
nationalPrefix = prefixMatch[0];
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
nationalNumber: nationalNumber,
|
|
93
|
+
nationalPrefix: nationalPrefix,
|
|
94
|
+
carrierCode: carrierCode
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
nationalNumber: number
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { extractNationalNumberFromPossiblyIncompleteNumber as default };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { VALID_DIGITS } from '../constants.js';
|
|
2
|
+
|
|
3
|
+
// When phone numbers are written in `RFC3966` format — `"tel:+12133734253"` —
|
|
4
|
+
// they can have their "calling code" part written separately in a `phone-context` parameter.
|
|
5
|
+
// Example: `"tel:12133734253;phone-context=+1"`.
|
|
6
|
+
// This function parses the full phone number from the local number and the `phone-context`
|
|
7
|
+
// when the `phone-context` contains a `+` sign.
|
|
8
|
+
|
|
9
|
+
var PLUS_SIGN = '+';
|
|
10
|
+
var RFC3966_VISUAL_SEPARATOR_ = '[\\-\\.\\(\\)]?';
|
|
11
|
+
var RFC3966_PHONE_DIGIT_ = '(' + '[' + VALID_DIGITS + ']' + '|' + RFC3966_VISUAL_SEPARATOR_ + ')';
|
|
12
|
+
var RFC3966_GLOBAL_NUMBER_DIGITS_ = '^' + '\\' + PLUS_SIGN + RFC3966_PHONE_DIGIT_ + '*' + '[' + VALID_DIGITS + ']' + RFC3966_PHONE_DIGIT_ + '*' + '$';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Regular expression of valid global-number-digits for the phone-context
|
|
16
|
+
* parameter, following the syntax defined in RFC3966.
|
|
17
|
+
*/
|
|
18
|
+
var RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_ = new RegExp(RFC3966_GLOBAL_NUMBER_DIGITS_, 'g');
|
|
19
|
+
|
|
20
|
+
// In this port of Google's library, we don't accept alpha characters in phone numbers.
|
|
21
|
+
// const ALPHANUM_ = VALID_ALPHA_ + VALID_DIGITS
|
|
22
|
+
var ALPHANUM_ = VALID_DIGITS;
|
|
23
|
+
var RFC3966_DOMAINLABEL_ = '[' + ALPHANUM_ + ']+((\\-)*[' + ALPHANUM_ + '])*';
|
|
24
|
+
var VALID_ALPHA_ = 'a-zA-Z';
|
|
25
|
+
var RFC3966_TOPLABEL_ = '[' + VALID_ALPHA_ + ']+((\\-)*[' + ALPHANUM_ + '])*';
|
|
26
|
+
var RFC3966_DOMAINNAME_ = '^(' + RFC3966_DOMAINLABEL_ + '\\.)*' + RFC3966_TOPLABEL_ + '\\.?$';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Regular expression of valid domainname for the phone-context parameter,
|
|
30
|
+
* following the syntax defined in RFC3966.
|
|
31
|
+
*/
|
|
32
|
+
var RFC3966_DOMAINNAME_PATTERN_ = new RegExp(RFC3966_DOMAINNAME_, 'g');
|
|
33
|
+
var RFC3966_PREFIX_ = 'tel:';
|
|
34
|
+
var RFC3966_PHONE_CONTEXT_ = ';phone-context=';
|
|
35
|
+
var RFC3966_ISDN_SUBADDRESS_ = ';isub=';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Extracts the value of the phone-context parameter of `numberToExtractFrom`,
|
|
39
|
+
* following the syntax defined in RFC3966.
|
|
40
|
+
*
|
|
41
|
+
* @param {string} numberToExtractFrom
|
|
42
|
+
* @return {string|null} the extracted string (possibly empty), or `null` if no phone-context parameter is found.
|
|
43
|
+
*/
|
|
44
|
+
function extractPhoneContext(numberToExtractFrom) {
|
|
45
|
+
var indexOfPhoneContext = numberToExtractFrom.indexOf(RFC3966_PHONE_CONTEXT_);
|
|
46
|
+
// If no phone-context parameter is present
|
|
47
|
+
if (indexOfPhoneContext < 0) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
var phoneContextStart = indexOfPhoneContext + RFC3966_PHONE_CONTEXT_.length;
|
|
51
|
+
// If phone-context parameter is empty
|
|
52
|
+
if (phoneContextStart >= numberToExtractFrom.length) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
var phoneContextEnd = numberToExtractFrom.indexOf(';', phoneContextStart);
|
|
56
|
+
// If phone-context is not the last parameter
|
|
57
|
+
if (phoneContextEnd >= 0) {
|
|
58
|
+
return numberToExtractFrom.substring(phoneContextStart, phoneContextEnd);
|
|
59
|
+
} else {
|
|
60
|
+
return numberToExtractFrom.substring(phoneContextStart);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns whether the value of phoneContext follows the syntax defined in RFC3966.
|
|
66
|
+
*
|
|
67
|
+
* @param {string|null} phoneContext
|
|
68
|
+
* @return {boolean}
|
|
69
|
+
*/
|
|
70
|
+
function isPhoneContextValid(phoneContext) {
|
|
71
|
+
if (phoneContext === null) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (phoneContext.length === 0) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Does phone-context value match pattern of global-number-digits or domainname.
|
|
79
|
+
return RFC3966_GLOBAL_NUMBER_DIGITS_PATTERN_.test(phoneContext) || RFC3966_DOMAINNAME_PATTERN_.test(phoneContext);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { PLUS_SIGN, RFC3966_ISDN_SUBADDRESS_, RFC3966_PHONE_CONTEXT_, RFC3966_PREFIX_, extractPhoneContext as default, isPhoneContextValid };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import applyInternationalSeparatorStyle from './applyInternationalSeparatorStyle.js';
|
|
2
|
+
|
|
3
|
+
// This was originally set to $1 but there are some countries for which the
|
|
4
|
+
// first group is not used in the national pattern (e.g. Argentina) so the $1
|
|
5
|
+
// group does not match correctly. Therefore, we use `\d`, so that the first
|
|
6
|
+
// group actually used in the pattern will be matched.
|
|
7
|
+
var FIRST_GROUP_PATTERN = /(\$\d)/;
|
|
8
|
+
function formatNationalNumberUsingFormat(number, format, _ref) {
|
|
9
|
+
var useInternationalFormat = _ref.useInternationalFormat,
|
|
10
|
+
withNationalPrefix = _ref.withNationalPrefix;
|
|
11
|
+
var formattedNumber = number.replace(new RegExp(format.pattern()), useInternationalFormat ? format.internationalFormat() :
|
|
12
|
+
// This library doesn't use `domestic_carrier_code_formatting_rule`,
|
|
13
|
+
// because that one is only used when formatting phone numbers
|
|
14
|
+
// for dialing from a mobile phone, and this is not a dialing library.
|
|
15
|
+
// carrierCode && format.domesticCarrierCodeFormattingRule()
|
|
16
|
+
// // First, replace the $CC in the formatting rule with the desired carrier code.
|
|
17
|
+
// // Then, replace the $FG in the formatting rule with the first group
|
|
18
|
+
// // and the carrier code combined in the appropriate way.
|
|
19
|
+
// ? format.format().replace(FIRST_GROUP_PATTERN, format.domesticCarrierCodeFormattingRule().replace('$CC', carrierCode))
|
|
20
|
+
// : (
|
|
21
|
+
// withNationalPrefix && format.nationalPrefixFormattingRule()
|
|
22
|
+
// ? format.format().replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule())
|
|
23
|
+
// : format.format()
|
|
24
|
+
// )
|
|
25
|
+
withNationalPrefix && format.nationalPrefixFormattingRule() ? format.format().replace(FIRST_GROUP_PATTERN, format.nationalPrefixFormattingRule()) : format.format());
|
|
26
|
+
if (useInternationalFormat) {
|
|
27
|
+
return applyInternationalSeparatorStyle(formattedNumber);
|
|
28
|
+
}
|
|
29
|
+
return formattedNumber;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { FIRST_GROUP_PATTERN, formatNationalNumberUsingFormat as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import getCountryByNationalNumber from './getCountryByNationalNumber.js';
|
|
2
|
+
|
|
3
|
+
// Returns the exact country for the `nationalNumber`
|
|
4
|
+
// that belongs to the specified "country calling code".
|
|
5
|
+
function getCountryByCallingCode(callingCode, _ref) {
|
|
6
|
+
var nationalPhoneNumber = _ref.nationalNumber,
|
|
7
|
+
metadata = _ref.metadata;
|
|
8
|
+
var possibleCountries = metadata.getCountryCodesForCallingCode(callingCode);
|
|
9
|
+
if (!possibleCountries) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
// If there's just one country corresponding to the country code,
|
|
13
|
+
// then just return it, without further phone number digits validation.
|
|
14
|
+
if (possibleCountries.length === 1) {
|
|
15
|
+
return possibleCountries[0];
|
|
16
|
+
}
|
|
17
|
+
return getCountryByNationalNumber(nationalPhoneNumber, {
|
|
18
|
+
countries: possibleCountries,
|
|
19
|
+
metadata: metadata.metadata
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getCountryByCallingCode as default };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Metadata from '../metadata.js';
|
|
2
|
+
import getNumberType from './getNumberType.js';
|
|
3
|
+
|
|
4
|
+
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: true } : { done: false, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
|
+
|
|
8
|
+
// Returns the exact country that the `nationalPhoneNumber` belongs to
|
|
9
|
+
// in cases of ambiguity, i.e. when multiple countries share the same "country calling code".
|
|
10
|
+
function getCountryByNationalNumber(nationalPhoneNumber, _ref) {
|
|
11
|
+
var countries = _ref.countries,
|
|
12
|
+
metadata = _ref.metadata;
|
|
13
|
+
// Re-create `metadata` because it will be selecting a `country`.
|
|
14
|
+
metadata = new Metadata(metadata);
|
|
15
|
+
|
|
16
|
+
// const matchingCountries = []
|
|
17
|
+
|
|
18
|
+
for (var _iterator = _createForOfIteratorHelperLoose(countries), _step; !(_step = _iterator()).done;) {
|
|
19
|
+
var country = _step.value;
|
|
20
|
+
metadata.selectNumberingPlan(country);
|
|
21
|
+
// "Leading digits" patterns are only defined for about 20% of all countries.
|
|
22
|
+
// By definition, matching "leading digits" is a sufficient but not a necessary
|
|
23
|
+
// condition for a phone number to belong to a country.
|
|
24
|
+
// The point of "leading digits" check is that it's the fastest one to get a match.
|
|
25
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md#leading_digits
|
|
26
|
+
// I'd suppose that "leading digits" patterns are mutually exclusive for different countries
|
|
27
|
+
// because of the intended use of that feature.
|
|
28
|
+
if (metadata.leadingDigits()) {
|
|
29
|
+
if (nationalPhoneNumber && nationalPhoneNumber.search(metadata.leadingDigits()) === 0) {
|
|
30
|
+
return country;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Else perform full validation with all of those
|
|
34
|
+
// fixed-line/mobile/etc regular expressions.
|
|
35
|
+
else if (getNumberType({
|
|
36
|
+
phone: nationalPhoneNumber,
|
|
37
|
+
country: country
|
|
38
|
+
}, undefined, metadata.metadata)) {
|
|
39
|
+
// When multiple countries share the same "country calling code",
|
|
40
|
+
// type patterns aren't guaranteed to be unique among them.
|
|
41
|
+
// For example, both `US` and `CA` have the same pattern for `toll_free` numbers.
|
|
42
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/103#note_1417147572
|
|
43
|
+
//
|
|
44
|
+
// That means that this `if` condition could be `true` for multiple countries from the list.
|
|
45
|
+
// Currently, it just returns the first one, which is also the "main" country for the "country calling code".
|
|
46
|
+
// In an example with `toll_free` numbers above, `"US"` would be returned even though
|
|
47
|
+
// it could as well be `"CA"`.
|
|
48
|
+
//
|
|
49
|
+
// There was also a time when this attempted to be overly smart
|
|
50
|
+
// and kept track of all such multiple matching countries
|
|
51
|
+
// and then picked the one that matched the `defaultCountry`, if provided.
|
|
52
|
+
// For example, with `toll_free` numbers above, and with `defaultCountry: "CA"`,
|
|
53
|
+
// it would've returned `"CA"` instead of `"US"`.
|
|
54
|
+
// Later it turned out that such "overly smart" behavior turned out to be just confusing,
|
|
55
|
+
// so this "overly smart" country detection was reverted to returning the "main" country
|
|
56
|
+
// for the "country calling code".
|
|
57
|
+
// https://gitlab.com/catamphetamine/libphonenumber-js/-/issues/154
|
|
58
|
+
//
|
|
59
|
+
return country;
|
|
60
|
+
//
|
|
61
|
+
// The "overly smart" behavior code:
|
|
62
|
+
//
|
|
63
|
+
// if (defaultCountry) {
|
|
64
|
+
// if (country === defaultCountry) {
|
|
65
|
+
// return country
|
|
66
|
+
// } else {
|
|
67
|
+
// matchingCountries.push(country)
|
|
68
|
+
// }
|
|
69
|
+
// } else {
|
|
70
|
+
// return country
|
|
71
|
+
// }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// // Return the first ("main") one of the `matchingCountries`.
|
|
76
|
+
// if (matchingCountries.length > 0) {
|
|
77
|
+
// return matchingCountries[0]
|
|
78
|
+
// }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { getCountryByNationalNumber as default };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Metadata from '../metadata.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pattern that makes it easy to distinguish whether a region has a single
|
|
5
|
+
* international dialing prefix or not. If a region has a single international
|
|
6
|
+
* prefix (e.g. 011 in USA), it will be represented as a string that contains
|
|
7
|
+
* a sequence of ASCII digits, and possibly a tilde, which signals waiting for
|
|
8
|
+
* the tone. If there are multiple available international prefixes in a
|
|
9
|
+
* region, they will be represented as a regex string that always contains one
|
|
10
|
+
* or more characters that are not ASCII digits or a tilde.
|
|
11
|
+
*/
|
|
12
|
+
var SINGLE_IDD_PREFIX_REG_EXP = /^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;
|
|
13
|
+
|
|
14
|
+
// If the `country` supports IDD calling, it returns a preferred IDD prefix.
|
|
15
|
+
// If the `country` doesn't support IDD calling, it returns `undefined`.
|
|
16
|
+
function getIddPrefix(country, callingCode, metadata) {
|
|
17
|
+
var countryMetadata = new Metadata(metadata);
|
|
18
|
+
countryMetadata.selectNumberingPlan(country, callingCode);
|
|
19
|
+
if (countryMetadata.defaultIDDPrefix()) {
|
|
20
|
+
return countryMetadata.defaultIDDPrefix();
|
|
21
|
+
}
|
|
22
|
+
if (SINGLE_IDD_PREFIX_REG_EXP.test(countryMetadata.IDDPrefix())) {
|
|
23
|
+
return countryMetadata.IDDPrefix();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { getIddPrefix as default };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import Metadata from '../metadata.js';
|
|
2
|
+
import matchesEntirely from './matchesEntirely.js';
|
|
3
|
+
|
|
4
|
+
function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: true } : { done: false, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
6
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
7
|
+
var NON_FIXED_LINE_PHONE_TYPES = ['MOBILE', 'PREMIUM_RATE', 'TOLL_FREE', 'SHARED_COST', 'VOIP', 'PERSONAL_NUMBER', 'PAGER', 'UAN', 'VOICEMAIL'];
|
|
8
|
+
|
|
9
|
+
// Finds out national phone number type (fixed line, mobile, etc)
|
|
10
|
+
function getNumberType(input, options, metadata) {
|
|
11
|
+
// If assigning the `{}` default value is moved to the arguments above,
|
|
12
|
+
// code coverage would decrease for some weird reason.
|
|
13
|
+
options = options || {};
|
|
14
|
+
|
|
15
|
+
// When `parse()` returns an empty object — `{}` —
|
|
16
|
+
// that means that the phone number is malformed,
|
|
17
|
+
// so it can't possibly be valid.
|
|
18
|
+
if (!input.country && !input.countryCallingCode) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
metadata = new Metadata(metadata);
|
|
22
|
+
metadata.selectNumberingPlan(input.country, input.countryCallingCode);
|
|
23
|
+
var nationalNumber = options.v2 ? input.nationalNumber : input.phone;
|
|
24
|
+
|
|
25
|
+
// The following is copy-pasted from the original function:
|
|
26
|
+
// https://github.com/googlei18n/libphonenumber/blob/3ea547d4fbaa2d0b67588904dfa5d3f2557c27ff/javascript/i18n/phonenumbers/phonenumberutil.js#L2835
|
|
27
|
+
|
|
28
|
+
// Is this national number even valid for this country
|
|
29
|
+
if (!matchesEntirely(nationalNumber, metadata.nationalNumberPattern())) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Is it fixed line number
|
|
34
|
+
if (isNumberTypeEqualTo(nationalNumber, 'FIXED_LINE', metadata)) {
|
|
35
|
+
// Because duplicate regular expressions are removed
|
|
36
|
+
// to reduce metadata size, if "mobile" pattern is ""
|
|
37
|
+
// then it means it was removed due to being a duplicate of the fixed-line pattern.
|
|
38
|
+
//
|
|
39
|
+
if (metadata.type('MOBILE') && metadata.type('MOBILE').pattern() === '') {
|
|
40
|
+
return 'FIXED_LINE_OR_MOBILE';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// `MOBILE` type pattern isn't included if it matched `FIXED_LINE` one.
|
|
44
|
+
// For example, for "US" country.
|
|
45
|
+
// Old metadata (< `1.0.18`) had a specific "types" data structure
|
|
46
|
+
// that happened to be `undefined` for `MOBILE` in that case.
|
|
47
|
+
// Newer metadata (>= `1.0.18`) has another data structure that is
|
|
48
|
+
// not `undefined` for `MOBILE` in that case (it's just an empty array).
|
|
49
|
+
// So this `if` is just for backwards compatibility with old metadata.
|
|
50
|
+
if (!metadata.type('MOBILE')) {
|
|
51
|
+
return 'FIXED_LINE_OR_MOBILE';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Check if the number happens to qualify as both fixed line and mobile.
|
|
55
|
+
// (no such country in the minimal metadata set)
|
|
56
|
+
/* istanbul ignore if */
|
|
57
|
+
if (isNumberTypeEqualTo(nationalNumber, 'MOBILE', metadata)) {
|
|
58
|
+
return 'FIXED_LINE_OR_MOBILE';
|
|
59
|
+
}
|
|
60
|
+
return 'FIXED_LINE';
|
|
61
|
+
}
|
|
62
|
+
for (var _iterator = _createForOfIteratorHelperLoose(NON_FIXED_LINE_PHONE_TYPES), _step; !(_step = _iterator()).done;) {
|
|
63
|
+
var type = _step.value;
|
|
64
|
+
if (isNumberTypeEqualTo(nationalNumber, type, metadata)) {
|
|
65
|
+
return type;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isNumberTypeEqualTo(nationalNumber, type, metadata) {
|
|
70
|
+
type = metadata.type(type);
|
|
71
|
+
if (!type || !type.pattern()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// Check if any possible number lengths are present;
|
|
75
|
+
// if so, we use them to avoid checking
|
|
76
|
+
// the validation pattern if they don't match.
|
|
77
|
+
// If they are absent, this means they match
|
|
78
|
+
// the general description, which we have
|
|
79
|
+
// already checked before a specific number type.
|
|
80
|
+
if (type.possibleLengths() && type.possibleLengths().indexOf(nationalNumber.length) < 0) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
return matchesEntirely(nationalNumber, type.pattern());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { getNumberType as default, isNumberTypeEqualTo };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Metadata from '../metadata.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a list of countries that the phone number could potentially belong to.
|
|
5
|
+
* @param {string} callingCode — Calling code.
|
|
6
|
+
* @param {string} nationalNumber — National (significant) number.
|
|
7
|
+
* @param {object} metadata — Metadata.
|
|
8
|
+
* @return {string[]} A list of possible countries.
|
|
9
|
+
*/
|
|
10
|
+
function getPossibleCountriesForNumber(callingCode, nationalNumber, metadata) {
|
|
11
|
+
var _metadata = new Metadata(metadata);
|
|
12
|
+
var possibleCountries = _metadata.getCountryCodesForCallingCode(callingCode);
|
|
13
|
+
if (!possibleCountries) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return possibleCountries.filter(function (country) {
|
|
17
|
+
return couldNationalNumberBelongToCountry(nationalNumber, country, metadata);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function couldNationalNumberBelongToCountry(nationalNumber, country, metadata) {
|
|
21
|
+
var _metadata = new Metadata(metadata);
|
|
22
|
+
_metadata.selectNumberingPlan(country);
|
|
23
|
+
if (_metadata.numberingPlan.possibleLengths().indexOf(nationalNumber.length) >= 0) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { getPossibleCountriesForNumber as default };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { MIN_LENGTH_FOR_NSN, VALID_DIGITS, PLUS_CHARS, VALID_PUNCTUATION } from '../constants.js';
|
|
2
|
+
import createExtensionPattern from './extension/createExtensionPattern.js';
|
|
3
|
+
|
|
4
|
+
// Regular expression of viable phone numbers. This is location independent.
|
|
5
|
+
// Checks we have at least three leading digits, and only valid punctuation,
|
|
6
|
+
// alpha characters and digits in the phone number. Does not include extension
|
|
7
|
+
// data. The symbol 'x' is allowed here as valid punctuation since it is often
|
|
8
|
+
// used as a placeholder for carrier codes, for example in Brazilian phone
|
|
9
|
+
// numbers. We also allow multiple '+' characters at the start.
|
|
10
|
+
//
|
|
11
|
+
// Corresponds to the following:
|
|
12
|
+
// [digits]{minLengthNsn}|
|
|
13
|
+
// plus_sign*
|
|
14
|
+
// (([punctuation]|[star])*[digits]){3,}([punctuation]|[star]|[digits]|[alpha])*
|
|
15
|
+
//
|
|
16
|
+
// The first reg-ex is to allow short numbers (two digits long) to be parsed if
|
|
17
|
+
// they are entered as "15" etc, but only if there is no punctuation in them.
|
|
18
|
+
// The second expression restricts the number of digits to three or more, but
|
|
19
|
+
// then allows them to be in international form, and to have alpha-characters
|
|
20
|
+
// and punctuation. We split up the two reg-exes here and combine them when
|
|
21
|
+
// creating the reg-ex VALID_PHONE_NUMBER_PATTERN itself so we can prefix it
|
|
22
|
+
// with ^ and append $ to each branch.
|
|
23
|
+
//
|
|
24
|
+
// "Note VALID_PUNCTUATION starts with a -,
|
|
25
|
+
// so must be the first in the range" (c) Google devs.
|
|
26
|
+
// (wtf did they mean by saying that; probably nothing)
|
|
27
|
+
//
|
|
28
|
+
var MIN_LENGTH_PHONE_NUMBER_PATTERN = '[' + VALID_DIGITS + ']{' + MIN_LENGTH_FOR_NSN + '}';
|
|
29
|
+
//
|
|
30
|
+
// And this is the second reg-exp:
|
|
31
|
+
// (see MIN_LENGTH_PHONE_NUMBER_PATTERN for a full description of this reg-exp)
|
|
32
|
+
//
|
|
33
|
+
var VALID_PHONE_NUMBER = '[' + PLUS_CHARS + ']{0,1}' + '(?:' + '[' + VALID_PUNCTUATION + ']*' + '[' + VALID_DIGITS + ']' + '){3,}' + '[' + VALID_PUNCTUATION + VALID_DIGITS + ']*';
|
|
34
|
+
|
|
35
|
+
// This regular expression isn't present in Google's `libphonenumber`
|
|
36
|
+
// and is only used to determine whether the phone number being input
|
|
37
|
+
// is too short for it to even consider it a "valid" number.
|
|
38
|
+
// This is just a way to differentiate between a really invalid phone
|
|
39
|
+
// number like "abcde" and a valid phone number that a user has just
|
|
40
|
+
// started inputting, like "+1" or "1": both these cases would be
|
|
41
|
+
// considered `NOT_A_NUMBER` by Google's `libphonenumber`, but this
|
|
42
|
+
// library can provide a more detailed error message — whether it's
|
|
43
|
+
// really "not a number", or is it just a start of a valid phone number.
|
|
44
|
+
var VALID_PHONE_NUMBER_START_REG_EXP = new RegExp('^' + '[' + PLUS_CHARS + ']{0,1}' + '(?:' + '[' + VALID_PUNCTUATION + ']*' + '[' + VALID_DIGITS + ']' + '){1,2}' + '$', 'i');
|
|
45
|
+
var VALID_PHONE_NUMBER_WITH_EXTENSION = VALID_PHONE_NUMBER +
|
|
46
|
+
// Phone number extensions
|
|
47
|
+
'(?:' + createExtensionPattern() + ')?';
|
|
48
|
+
|
|
49
|
+
// The combined regular expression for valid phone numbers:
|
|
50
|
+
//
|
|
51
|
+
var VALID_PHONE_NUMBER_PATTERN = new RegExp(
|
|
52
|
+
// Either a short two-digit-only phone number
|
|
53
|
+
'^' + MIN_LENGTH_PHONE_NUMBER_PATTERN + '$' + '|' +
|
|
54
|
+
// Or a longer fully parsed phone number (min 3 characters)
|
|
55
|
+
'^' + VALID_PHONE_NUMBER_WITH_EXTENSION + '$', 'i');
|
|
56
|
+
|
|
57
|
+
// Checks to see if the string of characters could possibly be a phone number at
|
|
58
|
+
// all. At the moment, checks to see that the string begins with at least 2
|
|
59
|
+
// digits, ignoring any punctuation commonly found in phone numbers. This method
|
|
60
|
+
// does not require the number to be normalized in advance - but does assume
|
|
61
|
+
// that leading non-number symbols have been removed, such as by the method
|
|
62
|
+
// `extract_possible_number`.
|
|
63
|
+
//
|
|
64
|
+
function isViablePhoneNumber(number) {
|
|
65
|
+
return number.length >= MIN_LENGTH_FOR_NSN && VALID_PHONE_NUMBER_PATTERN.test(number);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// This is just a way to differentiate between a really invalid phone
|
|
69
|
+
// number like "abcde" and a valid phone number that a user has just
|
|
70
|
+
// started inputting, like "+1" or "1": both these cases would be
|
|
71
|
+
// considered `NOT_A_NUMBER` by Google's `libphonenumber`, but this
|
|
72
|
+
// library can provide a more detailed error message — whether it's
|
|
73
|
+
// really "not a number", or is it just a start of a valid phone number.
|
|
74
|
+
function isViablePhoneNumberStart(number) {
|
|
75
|
+
return VALID_PHONE_NUMBER_START_REG_EXP.test(number);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { VALID_PHONE_NUMBER, VALID_PHONE_NUMBER_WITH_EXTENSION, isViablePhoneNumber as default, isViablePhoneNumberStart };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the entire input sequence can be matched
|
|
3
|
+
* against the regular expression.
|
|
4
|
+
* @return {boolean}
|
|
5
|
+
*/
|
|
6
|
+
function matchesEntirely(text, regularExpressionText) {
|
|
7
|
+
// If the assigning of the `''` default value is moved to the arguments above,
|
|
8
|
+
// the code coverage would decrease for some weird reason.
|
|
9
|
+
text = text || '';
|
|
10
|
+
return new RegExp('^(?:' + regularExpressionText + ')$').test(text);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { matchesEntirely as default };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// These mappings map a character (key) to a specific digit that should
|
|
2
|
+
// replace it for normalization purposes. Non-European digits that
|
|
3
|
+
// may be used in phone numbers are mapped to a European equivalent.
|
|
4
|
+
//
|
|
5
|
+
// E.g. in Iraq they don't write `+442323234` but rather `+٤٤٢٣٢٣٢٣٤`.
|
|
6
|
+
//
|
|
7
|
+
var DIGITS = {
|
|
8
|
+
'0': '0',
|
|
9
|
+
'1': '1',
|
|
10
|
+
'2': '2',
|
|
11
|
+
'3': '3',
|
|
12
|
+
'4': '4',
|
|
13
|
+
'5': '5',
|
|
14
|
+
'6': '6',
|
|
15
|
+
'7': '7',
|
|
16
|
+
'8': '8',
|
|
17
|
+
'9': '9',
|
|
18
|
+
"\uFF10": '0',
|
|
19
|
+
// Fullwidth digit 0
|
|
20
|
+
"\uFF11": '1',
|
|
21
|
+
// Fullwidth digit 1
|
|
22
|
+
"\uFF12": '2',
|
|
23
|
+
// Fullwidth digit 2
|
|
24
|
+
"\uFF13": '3',
|
|
25
|
+
// Fullwidth digit 3
|
|
26
|
+
"\uFF14": '4',
|
|
27
|
+
// Fullwidth digit 4
|
|
28
|
+
"\uFF15": '5',
|
|
29
|
+
// Fullwidth digit 5
|
|
30
|
+
"\uFF16": '6',
|
|
31
|
+
// Fullwidth digit 6
|
|
32
|
+
"\uFF17": '7',
|
|
33
|
+
// Fullwidth digit 7
|
|
34
|
+
"\uFF18": '8',
|
|
35
|
+
// Fullwidth digit 8
|
|
36
|
+
"\uFF19": '9',
|
|
37
|
+
// Fullwidth digit 9
|
|
38
|
+
"\u0660": '0',
|
|
39
|
+
// Arabic-indic digit 0
|
|
40
|
+
"\u0661": '1',
|
|
41
|
+
// Arabic-indic digit 1
|
|
42
|
+
"\u0662": '2',
|
|
43
|
+
// Arabic-indic digit 2
|
|
44
|
+
"\u0663": '3',
|
|
45
|
+
// Arabic-indic digit 3
|
|
46
|
+
"\u0664": '4',
|
|
47
|
+
// Arabic-indic digit 4
|
|
48
|
+
"\u0665": '5',
|
|
49
|
+
// Arabic-indic digit 5
|
|
50
|
+
"\u0666": '6',
|
|
51
|
+
// Arabic-indic digit 6
|
|
52
|
+
"\u0667": '7',
|
|
53
|
+
// Arabic-indic digit 7
|
|
54
|
+
"\u0668": '8',
|
|
55
|
+
// Arabic-indic digit 8
|
|
56
|
+
"\u0669": '9',
|
|
57
|
+
// Arabic-indic digit 9
|
|
58
|
+
"\u06F0": '0',
|
|
59
|
+
// Eastern-Arabic digit 0
|
|
60
|
+
"\u06F1": '1',
|
|
61
|
+
// Eastern-Arabic digit 1
|
|
62
|
+
"\u06F2": '2',
|
|
63
|
+
// Eastern-Arabic digit 2
|
|
64
|
+
"\u06F3": '3',
|
|
65
|
+
// Eastern-Arabic digit 3
|
|
66
|
+
"\u06F4": '4',
|
|
67
|
+
// Eastern-Arabic digit 4
|
|
68
|
+
"\u06F5": '5',
|
|
69
|
+
// Eastern-Arabic digit 5
|
|
70
|
+
"\u06F6": '6',
|
|
71
|
+
// Eastern-Arabic digit 6
|
|
72
|
+
"\u06F7": '7',
|
|
73
|
+
// Eastern-Arabic digit 7
|
|
74
|
+
"\u06F8": '8',
|
|
75
|
+
// Eastern-Arabic digit 8
|
|
76
|
+
"\u06F9": '9' // Eastern-Arabic digit 9
|
|
77
|
+
};
|
|
78
|
+
function parseDigit(character) {
|
|
79
|
+
return DIGITS[character];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { DIGITS, parseDigit };
|