ingeniuscliq-core 0.5.32 → 0.5.34
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/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/index.js +7 -0
- package/dist/_virtual/index2.js +3 -0
- package/dist/_virtual/index3.js +3 -0
- package/dist/components/common/form/FormPhone.d.ts +23 -0
- package/dist/components/common/form/FormPhone.d.ts.map +1 -0
- package/dist/components/common/form/FormPhone.js +129 -0
- package/dist/components/common/form/index.d.ts +1 -0
- package/dist/components/common/form/index.d.ts.map +1 -1
- package/dist/components/templates/CoreHomeLayout.js +1 -0
- package/dist/components/templates/CorePreviewLayout.js +1 -0
- package/dist/index.js +1 -0
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts +1 -1
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.d.ts.map +1 -1
- package/dist/modules/CoreShipment/classes/CoreShipmentBuilder.js +9 -6
- package/dist/modules/CoreShipment/services/base.d.ts +13 -1
- package/dist/modules/CoreShipment/services/base.d.ts.map +1 -1
- package/dist/modules/CoreShipment/types/CoreShipment.d.ts +14 -1
- package/dist/modules/CoreShipment/types/CoreShipment.d.ts.map +1 -1
- package/dist/node_modules/diacritics/index.js +327 -0
- package/dist/node_modules/i18n-iso-countries/codes.json.js +3 -0
- package/dist/node_modules/i18n-iso-countries/index.js +409 -0
- package/dist/node_modules/i18n-iso-countries/langs/en.json.js +8 -0
- package/dist/node_modules/i18n-iso-countries/langs/es.json.js +8 -0
- package/dist/node_modules/i18n-iso-countries/supportedLocales.json.js +82 -0
- package/dist/node_modules/libphonenumber-js/es6/getCountries.js +7 -0
- package/dist/node_modules/libphonenumber-js/es6/helpers/isObject.js +6 -0
- package/dist/node_modules/libphonenumber-js/es6/metadata.js +602 -0
- package/dist/node_modules/libphonenumber-js/es6/tools/semver-compare.js +28 -0
- package/dist/node_modules/libphonenumber-js/metadata.min.json.js +6 -0
- package/dist/node_modules/libphonenumber-js/min/exports/getCountries.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/getCountryCallingCode.js +8 -0
- package/dist/node_modules/libphonenumber-js/min/exports/withMetadataArgument.js +12 -0
- package/package.json +1 -1
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import compare from './tools/semver-compare.js';
|
|
2
|
+
import isObject from './helpers/isObject.js';
|
|
3
|
+
|
|
4
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
6
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
7
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", { writable: false }), e; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return (String )(t); }
|
|
10
|
+
|
|
11
|
+
// Added "idd_prefix" and "default_idd_prefix".
|
|
12
|
+
var V3 = '1.2.0';
|
|
13
|
+
|
|
14
|
+
// Moved `001` country code to "nonGeographic" section of metadata.
|
|
15
|
+
var V4 = '1.7.35';
|
|
16
|
+
var DEFAULT_EXT_PREFIX = ' ext. ';
|
|
17
|
+
var CALLING_CODE_REG_EXP = /^\d+$/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* See: https://gitlab.com/catamphetamine/libphonenumber-js/blob/master/METADATA.md
|
|
21
|
+
*/
|
|
22
|
+
var Metadata = /*#__PURE__*/function () {
|
|
23
|
+
function Metadata(metadata) {
|
|
24
|
+
_classCallCheck(this, Metadata);
|
|
25
|
+
validateMetadata(metadata);
|
|
26
|
+
this.metadata = metadata;
|
|
27
|
+
setVersion.call(this, metadata);
|
|
28
|
+
}
|
|
29
|
+
return _createClass(Metadata, [{
|
|
30
|
+
key: "getCountries",
|
|
31
|
+
value: function getCountries() {
|
|
32
|
+
return Object.keys(this.metadata.countries).filter(function (_) {
|
|
33
|
+
return _ !== '001';
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: "getCountryMetadata",
|
|
38
|
+
value: function getCountryMetadata(countryCode) {
|
|
39
|
+
return this.metadata.countries[countryCode];
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "nonGeographic",
|
|
43
|
+
value: function nonGeographic() {
|
|
44
|
+
if (this.v1 || this.v2 || this.v3) return;
|
|
45
|
+
// `nonGeographical` was a typo.
|
|
46
|
+
// It's present in metadata generated from `1.7.35` to `1.7.37`.
|
|
47
|
+
// The test case could be found by searching for "nonGeographical".
|
|
48
|
+
return this.metadata.nonGeographic || this.metadata.nonGeographical;
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "hasCountry",
|
|
52
|
+
value: function hasCountry(country) {
|
|
53
|
+
return this.getCountryMetadata(country) !== undefined;
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "hasCallingCode",
|
|
57
|
+
value: function hasCallingCode(callingCode) {
|
|
58
|
+
if (this.getCountryCodesForCallingCode(callingCode)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (this.nonGeographic()) {
|
|
62
|
+
if (this.nonGeographic()[callingCode]) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
// A hacky workaround for old custom metadata (generated before V4).
|
|
67
|
+
var countryCodes = this.countryCallingCodes()[callingCode];
|
|
68
|
+
if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: "isNonGeographicCallingCode",
|
|
75
|
+
value: function isNonGeographicCallingCode(callingCode) {
|
|
76
|
+
if (this.nonGeographic()) {
|
|
77
|
+
return this.nonGeographic()[callingCode] ? true : false;
|
|
78
|
+
} else {
|
|
79
|
+
return this.getCountryCodesForCallingCode(callingCode) ? false : true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Deprecated.
|
|
84
|
+
}, {
|
|
85
|
+
key: "country",
|
|
86
|
+
value: function country(countryCode) {
|
|
87
|
+
return this.selectNumberingPlan(countryCode);
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "selectNumberingPlan",
|
|
91
|
+
value: function selectNumberingPlan(countryCode, callingCode) {
|
|
92
|
+
// Supports just passing `callingCode` as the first argument.
|
|
93
|
+
if (countryCode && CALLING_CODE_REG_EXP.test(countryCode)) {
|
|
94
|
+
callingCode = countryCode;
|
|
95
|
+
countryCode = null;
|
|
96
|
+
}
|
|
97
|
+
if (countryCode && countryCode !== '001') {
|
|
98
|
+
if (!this.hasCountry(countryCode)) {
|
|
99
|
+
throw new Error("Unknown country: ".concat(countryCode));
|
|
100
|
+
}
|
|
101
|
+
this.numberingPlan = new NumberingPlan(this.getCountryMetadata(countryCode), this);
|
|
102
|
+
} else if (callingCode) {
|
|
103
|
+
if (!this.hasCallingCode(callingCode)) {
|
|
104
|
+
throw new Error("Unknown calling code: ".concat(callingCode));
|
|
105
|
+
}
|
|
106
|
+
this.numberingPlan = new NumberingPlan(this.getNumberingPlanMetadata(callingCode), this);
|
|
107
|
+
} else {
|
|
108
|
+
this.numberingPlan = undefined;
|
|
109
|
+
}
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "getCountryCodesForCallingCode",
|
|
114
|
+
value: function getCountryCodesForCallingCode(callingCode) {
|
|
115
|
+
var countryCodes = this.countryCallingCodes()[callingCode];
|
|
116
|
+
if (countryCodes) {
|
|
117
|
+
// Metadata before V4 included "non-geographic entity" calling codes
|
|
118
|
+
// inside `country_calling_codes` (for example, `"881":["001"]`).
|
|
119
|
+
// Now the semantics of `country_calling_codes` has changed:
|
|
120
|
+
// it's specifically for "countries" now.
|
|
121
|
+
// Older versions of custom metadata will simply skip parsing
|
|
122
|
+
// "non-geographic entity" phone numbers with new versions
|
|
123
|
+
// of this library: it's not considered a bug,
|
|
124
|
+
// because such numbers are extremely rare,
|
|
125
|
+
// and developers extremely rarely use custom metadata.
|
|
126
|
+
if (countryCodes.length === 1 && countryCodes[0].length === 3) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
return countryCodes;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
133
|
+
key: "getCountryCodeForCallingCode",
|
|
134
|
+
value: function getCountryCodeForCallingCode(callingCode) {
|
|
135
|
+
var countryCodes = this.getCountryCodesForCallingCode(callingCode);
|
|
136
|
+
if (countryCodes) {
|
|
137
|
+
return countryCodes[0];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}, {
|
|
141
|
+
key: "getNumberingPlanMetadata",
|
|
142
|
+
value: function getNumberingPlanMetadata(callingCode) {
|
|
143
|
+
var countryCode = this.getCountryCodeForCallingCode(callingCode);
|
|
144
|
+
if (countryCode) {
|
|
145
|
+
return this.getCountryMetadata(countryCode);
|
|
146
|
+
}
|
|
147
|
+
if (this.nonGeographic()) {
|
|
148
|
+
var metadata = this.nonGeographic()[callingCode];
|
|
149
|
+
if (metadata) {
|
|
150
|
+
return metadata;
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
// A hacky workaround for old custom metadata (generated before V4).
|
|
154
|
+
// In that metadata, there was no concept of "non-geographic" metadata
|
|
155
|
+
// so metadata for `001` country code was stored along with other countries.
|
|
156
|
+
// The test case can be found by searching for:
|
|
157
|
+
// "should work around `nonGeographic` metadata not existing".
|
|
158
|
+
var countryCodes = this.countryCallingCodes()[callingCode];
|
|
159
|
+
if (countryCodes && countryCodes.length === 1 && countryCodes[0] === '001') {
|
|
160
|
+
return this.metadata.countries['001'];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Deprecated.
|
|
166
|
+
}, {
|
|
167
|
+
key: "countryCallingCode",
|
|
168
|
+
value: function countryCallingCode() {
|
|
169
|
+
return this.numberingPlan.callingCode();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Deprecated.
|
|
173
|
+
}, {
|
|
174
|
+
key: "IDDPrefix",
|
|
175
|
+
value: function IDDPrefix() {
|
|
176
|
+
return this.numberingPlan.IDDPrefix();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Deprecated.
|
|
180
|
+
}, {
|
|
181
|
+
key: "defaultIDDPrefix",
|
|
182
|
+
value: function defaultIDDPrefix() {
|
|
183
|
+
return this.numberingPlan.defaultIDDPrefix();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Deprecated.
|
|
187
|
+
}, {
|
|
188
|
+
key: "nationalNumberPattern",
|
|
189
|
+
value: function nationalNumberPattern() {
|
|
190
|
+
return this.numberingPlan.nationalNumberPattern();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Deprecated.
|
|
194
|
+
}, {
|
|
195
|
+
key: "possibleLengths",
|
|
196
|
+
value: function possibleLengths() {
|
|
197
|
+
return this.numberingPlan.possibleLengths();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Deprecated.
|
|
201
|
+
}, {
|
|
202
|
+
key: "formats",
|
|
203
|
+
value: function formats() {
|
|
204
|
+
return this.numberingPlan.formats();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Deprecated.
|
|
208
|
+
}, {
|
|
209
|
+
key: "nationalPrefixForParsing",
|
|
210
|
+
value: function nationalPrefixForParsing() {
|
|
211
|
+
return this.numberingPlan.nationalPrefixForParsing();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Deprecated.
|
|
215
|
+
}, {
|
|
216
|
+
key: "nationalPrefixTransformRule",
|
|
217
|
+
value: function nationalPrefixTransformRule() {
|
|
218
|
+
return this.numberingPlan.nationalPrefixTransformRule();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// Deprecated.
|
|
222
|
+
}, {
|
|
223
|
+
key: "leadingDigits",
|
|
224
|
+
value: function leadingDigits() {
|
|
225
|
+
return this.numberingPlan.leadingDigits();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Deprecated.
|
|
229
|
+
}, {
|
|
230
|
+
key: "hasTypes",
|
|
231
|
+
value: function hasTypes() {
|
|
232
|
+
return this.numberingPlan.hasTypes();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Deprecated.
|
|
236
|
+
}, {
|
|
237
|
+
key: "type",
|
|
238
|
+
value: function type(_type) {
|
|
239
|
+
return this.numberingPlan.type(_type);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Deprecated.
|
|
243
|
+
}, {
|
|
244
|
+
key: "ext",
|
|
245
|
+
value: function ext() {
|
|
246
|
+
return this.numberingPlan.ext();
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "countryCallingCodes",
|
|
250
|
+
value: function countryCallingCodes() {
|
|
251
|
+
if (this.v1) return this.metadata.country_phone_code_to_countries;
|
|
252
|
+
return this.metadata.country_calling_codes;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Deprecated.
|
|
256
|
+
}, {
|
|
257
|
+
key: "chooseCountryByCountryCallingCode",
|
|
258
|
+
value: function chooseCountryByCountryCallingCode(callingCode) {
|
|
259
|
+
return this.selectNumberingPlan(callingCode);
|
|
260
|
+
}
|
|
261
|
+
}, {
|
|
262
|
+
key: "hasSelectedNumberingPlan",
|
|
263
|
+
value: function hasSelectedNumberingPlan() {
|
|
264
|
+
return this.numberingPlan !== undefined;
|
|
265
|
+
}
|
|
266
|
+
}]);
|
|
267
|
+
}();
|
|
268
|
+
var NumberingPlan = /*#__PURE__*/function () {
|
|
269
|
+
function NumberingPlan(metadata, globalMetadataObject) {
|
|
270
|
+
_classCallCheck(this, NumberingPlan);
|
|
271
|
+
this.globalMetadataObject = globalMetadataObject;
|
|
272
|
+
this.metadata = metadata;
|
|
273
|
+
setVersion.call(this, globalMetadataObject.metadata);
|
|
274
|
+
}
|
|
275
|
+
return _createClass(NumberingPlan, [{
|
|
276
|
+
key: "callingCode",
|
|
277
|
+
value: function callingCode() {
|
|
278
|
+
return this.metadata[0];
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Formatting information for regions which share
|
|
282
|
+
// a country calling code is contained by only one region
|
|
283
|
+
// for performance reasons. For example, for NANPA region
|
|
284
|
+
// ("North American Numbering Plan Administration",
|
|
285
|
+
// which includes USA, Canada, Cayman Islands, Bahamas, etc)
|
|
286
|
+
// it will be contained in the metadata for `US`.
|
|
287
|
+
}, {
|
|
288
|
+
key: "getDefaultCountryMetadataForRegion",
|
|
289
|
+
value: function getDefaultCountryMetadataForRegion() {
|
|
290
|
+
return this.globalMetadataObject.getNumberingPlanMetadata(this.callingCode());
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Is always present.
|
|
294
|
+
}, {
|
|
295
|
+
key: "IDDPrefix",
|
|
296
|
+
value: function IDDPrefix() {
|
|
297
|
+
if (this.v1 || this.v2) return;
|
|
298
|
+
return this.metadata[1];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Is only present when a country supports multiple IDD prefixes.
|
|
302
|
+
}, {
|
|
303
|
+
key: "defaultIDDPrefix",
|
|
304
|
+
value: function defaultIDDPrefix() {
|
|
305
|
+
if (this.v1 || this.v2) return;
|
|
306
|
+
return this.metadata[12];
|
|
307
|
+
}
|
|
308
|
+
}, {
|
|
309
|
+
key: "nationalNumberPattern",
|
|
310
|
+
value: function nationalNumberPattern() {
|
|
311
|
+
if (this.v1 || this.v2) return this.metadata[1];
|
|
312
|
+
return this.metadata[2];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// "possible length" data is always present in Google's metadata.
|
|
316
|
+
}, {
|
|
317
|
+
key: "possibleLengths",
|
|
318
|
+
value: function possibleLengths() {
|
|
319
|
+
if (this.v1) return;
|
|
320
|
+
return this.metadata[this.v2 ? 2 : 3];
|
|
321
|
+
}
|
|
322
|
+
}, {
|
|
323
|
+
key: "_getFormats",
|
|
324
|
+
value: function _getFormats(metadata) {
|
|
325
|
+
return metadata[this.v1 ? 2 : this.v2 ? 3 : 4];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// For countries of the same region (e.g. NANPA)
|
|
329
|
+
// formats are all stored in the "main" country for that region.
|
|
330
|
+
// E.g. "RU" and "KZ", "US" and "CA".
|
|
331
|
+
}, {
|
|
332
|
+
key: "formats",
|
|
333
|
+
value: function formats() {
|
|
334
|
+
var _this = this;
|
|
335
|
+
var formats = this._getFormats(this.metadata) || this._getFormats(this.getDefaultCountryMetadataForRegion()) || [];
|
|
336
|
+
return formats.map(function (_) {
|
|
337
|
+
return new Format(_, _this);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}, {
|
|
341
|
+
key: "nationalPrefix",
|
|
342
|
+
value: function nationalPrefix() {
|
|
343
|
+
return this.metadata[this.v1 ? 3 : this.v2 ? 4 : 5];
|
|
344
|
+
}
|
|
345
|
+
}, {
|
|
346
|
+
key: "_getNationalPrefixFormattingRule",
|
|
347
|
+
value: function _getNationalPrefixFormattingRule(metadata) {
|
|
348
|
+
return metadata[this.v1 ? 4 : this.v2 ? 5 : 6];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// For countries of the same region (e.g. NANPA)
|
|
352
|
+
// national prefix formatting rule is stored in the "main" country for that region.
|
|
353
|
+
// E.g. "RU" and "KZ", "US" and "CA".
|
|
354
|
+
}, {
|
|
355
|
+
key: "nationalPrefixFormattingRule",
|
|
356
|
+
value: function nationalPrefixFormattingRule() {
|
|
357
|
+
return this._getNationalPrefixFormattingRule(this.metadata) || this._getNationalPrefixFormattingRule(this.getDefaultCountryMetadataForRegion());
|
|
358
|
+
}
|
|
359
|
+
}, {
|
|
360
|
+
key: "_nationalPrefixForParsing",
|
|
361
|
+
value: function _nationalPrefixForParsing() {
|
|
362
|
+
return this.metadata[this.v1 ? 5 : this.v2 ? 6 : 7];
|
|
363
|
+
}
|
|
364
|
+
}, {
|
|
365
|
+
key: "nationalPrefixForParsing",
|
|
366
|
+
value: function nationalPrefixForParsing() {
|
|
367
|
+
// If `national_prefix_for_parsing` is not set explicitly,
|
|
368
|
+
// then infer it from `national_prefix` (if any)
|
|
369
|
+
return this._nationalPrefixForParsing() || this.nationalPrefix();
|
|
370
|
+
}
|
|
371
|
+
}, {
|
|
372
|
+
key: "nationalPrefixTransformRule",
|
|
373
|
+
value: function nationalPrefixTransformRule() {
|
|
374
|
+
return this.metadata[this.v1 ? 6 : this.v2 ? 7 : 8];
|
|
375
|
+
}
|
|
376
|
+
}, {
|
|
377
|
+
key: "_getNationalPrefixIsOptionalWhenFormatting",
|
|
378
|
+
value: function _getNationalPrefixIsOptionalWhenFormatting() {
|
|
379
|
+
return !!this.metadata[this.v1 ? 7 : this.v2 ? 8 : 9];
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// For countries of the same region (e.g. NANPA)
|
|
383
|
+
// "national prefix is optional when formatting" flag is
|
|
384
|
+
// stored in the "main" country for that region.
|
|
385
|
+
// E.g. "RU" and "KZ", "US" and "CA".
|
|
386
|
+
}, {
|
|
387
|
+
key: "nationalPrefixIsOptionalWhenFormattingInNationalFormat",
|
|
388
|
+
value: function nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
389
|
+
return this._getNationalPrefixIsOptionalWhenFormatting(this.metadata) || this._getNationalPrefixIsOptionalWhenFormatting(this.getDefaultCountryMetadataForRegion());
|
|
390
|
+
}
|
|
391
|
+
}, {
|
|
392
|
+
key: "leadingDigits",
|
|
393
|
+
value: function leadingDigits() {
|
|
394
|
+
return this.metadata[this.v1 ? 8 : this.v2 ? 9 : 10];
|
|
395
|
+
}
|
|
396
|
+
}, {
|
|
397
|
+
key: "types",
|
|
398
|
+
value: function types() {
|
|
399
|
+
return this.metadata[this.v1 ? 9 : this.v2 ? 10 : 11];
|
|
400
|
+
}
|
|
401
|
+
}, {
|
|
402
|
+
key: "hasTypes",
|
|
403
|
+
value: function hasTypes() {
|
|
404
|
+
// Versions 1.2.0 - 1.2.4: can be `[]`.
|
|
405
|
+
/* istanbul ignore next */
|
|
406
|
+
if (this.types() && this.types().length === 0) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
// Versions <= 1.2.4: can be `undefined`.
|
|
410
|
+
// Version >= 1.2.5: can be `0`.
|
|
411
|
+
return !!this.types();
|
|
412
|
+
}
|
|
413
|
+
}, {
|
|
414
|
+
key: "type",
|
|
415
|
+
value: function type(_type2) {
|
|
416
|
+
if (this.hasTypes() && getType(this.types(), _type2)) {
|
|
417
|
+
return new Type(getType(this.types(), _type2), this);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}, {
|
|
421
|
+
key: "ext",
|
|
422
|
+
value: function ext() {
|
|
423
|
+
if (this.v1 || this.v2) return DEFAULT_EXT_PREFIX;
|
|
424
|
+
return this.metadata[13] || DEFAULT_EXT_PREFIX;
|
|
425
|
+
}
|
|
426
|
+
}]);
|
|
427
|
+
}();
|
|
428
|
+
var Format = /*#__PURE__*/function () {
|
|
429
|
+
function Format(format, metadata) {
|
|
430
|
+
_classCallCheck(this, Format);
|
|
431
|
+
this._format = format;
|
|
432
|
+
this.metadata = metadata;
|
|
433
|
+
}
|
|
434
|
+
return _createClass(Format, [{
|
|
435
|
+
key: "pattern",
|
|
436
|
+
value: function pattern() {
|
|
437
|
+
return this._format[0];
|
|
438
|
+
}
|
|
439
|
+
}, {
|
|
440
|
+
key: "format",
|
|
441
|
+
value: function format() {
|
|
442
|
+
return this._format[1];
|
|
443
|
+
}
|
|
444
|
+
}, {
|
|
445
|
+
key: "leadingDigitsPatterns",
|
|
446
|
+
value: function leadingDigitsPatterns() {
|
|
447
|
+
return this._format[2] || [];
|
|
448
|
+
}
|
|
449
|
+
}, {
|
|
450
|
+
key: "nationalPrefixFormattingRule",
|
|
451
|
+
value: function nationalPrefixFormattingRule() {
|
|
452
|
+
return this._format[3] || this.metadata.nationalPrefixFormattingRule();
|
|
453
|
+
}
|
|
454
|
+
}, {
|
|
455
|
+
key: "nationalPrefixIsOptionalWhenFormattingInNationalFormat",
|
|
456
|
+
value: function nationalPrefixIsOptionalWhenFormattingInNationalFormat() {
|
|
457
|
+
return !!this._format[4] || this.metadata.nationalPrefixIsOptionalWhenFormattingInNationalFormat();
|
|
458
|
+
}
|
|
459
|
+
}, {
|
|
460
|
+
key: "nationalPrefixIsMandatoryWhenFormattingInNationalFormat",
|
|
461
|
+
value: function nationalPrefixIsMandatoryWhenFormattingInNationalFormat() {
|
|
462
|
+
// National prefix is omitted if there's no national prefix formatting rule
|
|
463
|
+
// set for this country, or when the national prefix formatting rule
|
|
464
|
+
// contains no national prefix itself, or when this rule is set but
|
|
465
|
+
// national prefix is optional for this phone number format
|
|
466
|
+
// (and it is not enforced explicitly)
|
|
467
|
+
return this.usesNationalPrefix() && !this.nationalPrefixIsOptionalWhenFormattingInNationalFormat();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Checks whether national prefix formatting rule contains national prefix.
|
|
471
|
+
}, {
|
|
472
|
+
key: "usesNationalPrefix",
|
|
473
|
+
value: function usesNationalPrefix() {
|
|
474
|
+
return this.nationalPrefixFormattingRule() &&
|
|
475
|
+
// Check that national prefix formatting rule is not a "dummy" one.
|
|
476
|
+
!FIRST_GROUP_ONLY_PREFIX_PATTERN.test(this.nationalPrefixFormattingRule())
|
|
477
|
+
// In compressed metadata, `this.nationalPrefixFormattingRule()` is `0`
|
|
478
|
+
// when `national_prefix_formatting_rule` is not present.
|
|
479
|
+
// So, `true` or `false` are returned explicitly here, so that
|
|
480
|
+
// `0` number isn't returned.
|
|
481
|
+
? true : false;
|
|
482
|
+
}
|
|
483
|
+
}, {
|
|
484
|
+
key: "internationalFormat",
|
|
485
|
+
value: function internationalFormat() {
|
|
486
|
+
return this._format[5] || this.format();
|
|
487
|
+
}
|
|
488
|
+
}]);
|
|
489
|
+
}();
|
|
490
|
+
/**
|
|
491
|
+
* A pattern that is used to determine if the national prefix formatting rule
|
|
492
|
+
* has the first group only, i.e., does not start with the national prefix.
|
|
493
|
+
* Note that the pattern explicitly allows for unbalanced parentheses.
|
|
494
|
+
*/
|
|
495
|
+
var FIRST_GROUP_ONLY_PREFIX_PATTERN = /^\(?\$1\)?$/;
|
|
496
|
+
var Type = /*#__PURE__*/function () {
|
|
497
|
+
function Type(type, metadata) {
|
|
498
|
+
_classCallCheck(this, Type);
|
|
499
|
+
this.type = type;
|
|
500
|
+
this.metadata = metadata;
|
|
501
|
+
}
|
|
502
|
+
return _createClass(Type, [{
|
|
503
|
+
key: "pattern",
|
|
504
|
+
value: function pattern() {
|
|
505
|
+
if (this.metadata.v1) return this.type;
|
|
506
|
+
return this.type[0];
|
|
507
|
+
}
|
|
508
|
+
}, {
|
|
509
|
+
key: "possibleLengths",
|
|
510
|
+
value: function possibleLengths() {
|
|
511
|
+
if (this.metadata.v1) return;
|
|
512
|
+
return this.type[1] || this.metadata.possibleLengths();
|
|
513
|
+
}
|
|
514
|
+
}]);
|
|
515
|
+
}();
|
|
516
|
+
function getType(types, type) {
|
|
517
|
+
switch (type) {
|
|
518
|
+
case 'FIXED_LINE':
|
|
519
|
+
return types[0];
|
|
520
|
+
case 'MOBILE':
|
|
521
|
+
return types[1];
|
|
522
|
+
case 'TOLL_FREE':
|
|
523
|
+
return types[2];
|
|
524
|
+
case 'PREMIUM_RATE':
|
|
525
|
+
return types[3];
|
|
526
|
+
case 'PERSONAL_NUMBER':
|
|
527
|
+
return types[4];
|
|
528
|
+
case 'VOICEMAIL':
|
|
529
|
+
return types[5];
|
|
530
|
+
case 'UAN':
|
|
531
|
+
return types[6];
|
|
532
|
+
case 'PAGER':
|
|
533
|
+
return types[7];
|
|
534
|
+
case 'VOIP':
|
|
535
|
+
return types[8];
|
|
536
|
+
case 'SHARED_COST':
|
|
537
|
+
return types[9];
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function validateMetadata(metadata) {
|
|
541
|
+
if (!metadata) {
|
|
542
|
+
throw new Error('[libphonenumber-js] `metadata` argument not passed. Check your arguments.');
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// `country_phone_code_to_countries` was renamed to `country_calling_codes` in `1.0.18`.
|
|
546
|
+
// For that reason, it's not used in this detection algorithm.
|
|
547
|
+
// Instead, it detects by `countries: {}` property existence.
|
|
548
|
+
if (!isObject(metadata) || !isObject(metadata.countries)) {
|
|
549
|
+
throw new Error("[libphonenumber-js] `metadata` argument was passed but it's not a valid metadata. Must be an object having `.countries` child object property. Got ".concat(isObject(metadata) ? 'an object of shape: { ' + Object.keys(metadata).join(', ') + ' }' : 'a ' + typeOf(metadata) + ': ' + metadata, "."));
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Babel transforms `typeof` into some "branches"
|
|
554
|
+
// so istanbul will show this as "branch not covered".
|
|
555
|
+
/* istanbul ignore next */
|
|
556
|
+
var typeOf = function typeOf(_) {
|
|
557
|
+
return _typeof(_);
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Returns "country calling code" for a country.
|
|
562
|
+
* Throws an error if the country doesn't exist or isn't supported by this library.
|
|
563
|
+
* @param {string} country
|
|
564
|
+
* @param {object} metadata
|
|
565
|
+
* @return {string}
|
|
566
|
+
* @example
|
|
567
|
+
* // Returns "44"
|
|
568
|
+
* getCountryCallingCode("GB")
|
|
569
|
+
*/
|
|
570
|
+
function getCountryCallingCode(country, metadata) {
|
|
571
|
+
metadata = new Metadata(metadata);
|
|
572
|
+
if (metadata.hasCountry(country)) {
|
|
573
|
+
return metadata.selectNumberingPlan(country).countryCallingCode();
|
|
574
|
+
}
|
|
575
|
+
throw new Error("Unknown country: ".concat(country));
|
|
576
|
+
}
|
|
577
|
+
function setVersion(metadata) {
|
|
578
|
+
var version = metadata.version;
|
|
579
|
+
if (typeof version === 'number') {
|
|
580
|
+
this.v1 = version === 1;
|
|
581
|
+
this.v2 = version === 2;
|
|
582
|
+
this.v3 = version === 3;
|
|
583
|
+
this.v4 = version === 4;
|
|
584
|
+
} else {
|
|
585
|
+
if (!version) {
|
|
586
|
+
this.v1 = true;
|
|
587
|
+
} else if (compare(version, V3) === -1) {
|
|
588
|
+
this.v2 = true;
|
|
589
|
+
} else if (compare(version, V4) === -1) {
|
|
590
|
+
this.v3 = true;
|
|
591
|
+
} else {
|
|
592
|
+
this.v4 = true;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// const ISO_COUNTRY_CODE = /^[A-Z]{2}$/
|
|
598
|
+
// function isCountryCode(countryCode) {
|
|
599
|
+
// return ISO_COUNTRY_CODE.test(countryCodeOrCountryCallingCode)
|
|
600
|
+
// }
|
|
601
|
+
|
|
602
|
+
export { Metadata as default, getCountryCallingCode, validateMetadata };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copy-pasted from:
|
|
2
|
+
// https://github.com/substack/semver-compare/blob/master/index.js
|
|
3
|
+
//
|
|
4
|
+
// Inlining this function because some users reported issues with
|
|
5
|
+
// importing from `semver-compare` in a browser with ES6 "native" modules.
|
|
6
|
+
//
|
|
7
|
+
// Fixes `semver-compare` not being able to compare versions with alpha/beta/etc "tags".
|
|
8
|
+
// https://github.com/catamphetamine/libphonenumber-js/issues/381
|
|
9
|
+
function compare (a, b) {
|
|
10
|
+
a = a.split('-');
|
|
11
|
+
b = b.split('-');
|
|
12
|
+
var pa = a[0].split('.');
|
|
13
|
+
var pb = b[0].split('.');
|
|
14
|
+
for (var i = 0; i < 3; i++) {
|
|
15
|
+
var na = Number(pa[i]);
|
|
16
|
+
var nb = Number(pb[i]);
|
|
17
|
+
if (na > nb) return 1;
|
|
18
|
+
if (nb > na) return -1;
|
|
19
|
+
if (!isNaN(na) && isNaN(nb)) return 1;
|
|
20
|
+
if (isNaN(na) && !isNaN(nb)) return -1;
|
|
21
|
+
}
|
|
22
|
+
if (a[1] && b[1]) {
|
|
23
|
+
return a[1] > b[1] ? 1 : a[1] < b[1] ? -1 : 0;
|
|
24
|
+
}
|
|
25
|
+
return !a[1] && b[1] ? 1 : a[1] && !b[1] ? -1 : 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { compare as default };
|