UNPKG

4.05 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = parsePhoneNumber;
7exports.normalizeArguments = normalizeArguments;
8
9var _parsePhoneNumber_ = _interopRequireDefault(require("./parsePhoneNumber_"));
10
11function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
13function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
14
15function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
16
17function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
19function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
20
21function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
22
23function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
24
25function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
27function parsePhoneNumber() {
28 var _normalizeArguments = normalizeArguments(arguments),
29 text = _normalizeArguments.text,
30 options = _normalizeArguments.options,
31 metadata = _normalizeArguments.metadata;
32
33 return (0, _parsePhoneNumber_["default"])(text, options, metadata);
34}
35
36function normalizeArguments(args) {
37 var _Array$prototype$slic = Array.prototype.slice.call(args),
38 _Array$prototype$slic2 = _slicedToArray(_Array$prototype$slic, 4),
39 arg_1 = _Array$prototype$slic2[0],
40 arg_2 = _Array$prototype$slic2[1],
41 arg_3 = _Array$prototype$slic2[2],
42 arg_4 = _Array$prototype$slic2[3];
43
44 var text;
45 var options;
46 var metadata; // If the phone number is passed as a string.
47 // `parsePhoneNumber('88005553535', ...)`.
48
49 if (typeof arg_1 === 'string') {
50 text = arg_1;
51 } else throw new TypeError('A text for parsing must be a string.'); // If "default country" argument is being passed then move it to `options`.
52 // `parsePhoneNumber('88005553535', 'RU', [options], metadata)`.
53
54
55 if (!arg_2 || typeof arg_2 === 'string') {
56 if (arg_4) {
57 options = arg_3;
58 metadata = arg_4;
59 } else {
60 options = undefined;
61 metadata = arg_3;
62 }
63
64 if (arg_2) {
65 options = _objectSpread({
66 defaultCountry: arg_2
67 }, options);
68 }
69 } // `defaultCountry` is not passed.
70 // Example: `parsePhoneNumber('+78005553535', [options], metadata)`.
71 else if (isObject(arg_2)) {
72 if (arg_3) {
73 options = arg_2;
74 metadata = arg_3;
75 } else {
76 metadata = arg_2;
77 }
78 } else throw new Error("Invalid second argument: ".concat(arg_2));
79
80 return {
81 text: text,
82 options: options,
83 metadata: metadata
84 };
85} // Otherwise istanbul would show this as "branch not covered".
86
87/* istanbul ignore next */
88
89
90var isObject = function isObject(_) {
91 return _typeof(_) === 'object';
92};
93//# sourceMappingURL=parsePhoneNumber.js.map
\No newline at end of file