1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports["default"] = formatNumber;
|
7 |
|
8 | var _format_ = _interopRequireDefault(require("./format_"));
|
9 |
|
10 | var _parse_ = _interopRequireDefault(require("./parse_"));
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
13 |
|
14 | function _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); }
|
15 |
|
16 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
17 |
|
18 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
19 |
|
20 | function _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; }
|
21 |
|
22 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
23 |
|
24 | function formatNumber() {
|
25 | var _normalizeArguments = normalizeArguments(arguments),
|
26 | input = _normalizeArguments.input,
|
27 | format = _normalizeArguments.format,
|
28 | options = _normalizeArguments.options,
|
29 | metadata = _normalizeArguments.metadata;
|
30 |
|
31 | return (0, _format_["default"])(input, format, options, metadata);
|
32 | }
|
33 |
|
34 |
|
35 | function normalizeArguments(args) {
|
36 | var _Array$prototype$slic = Array.prototype.slice.call(args),
|
37 | _Array$prototype$slic2 = _slicedToArray(_Array$prototype$slic, 5),
|
38 | arg_1 = _Array$prototype$slic2[0],
|
39 | arg_2 = _Array$prototype$slic2[1],
|
40 | arg_3 = _Array$prototype$slic2[2],
|
41 | arg_4 = _Array$prototype$slic2[3],
|
42 | arg_5 = _Array$prototype$slic2[4];
|
43 |
|
44 | var input;
|
45 | var format;
|
46 | var options;
|
47 | var metadata;
|
48 |
|
49 |
|
50 |
|
51 | if (typeof arg_1 === 'string') {
|
52 |
|
53 |
|
54 | if (typeof arg_3 === 'string') {
|
55 | format = arg_3;
|
56 |
|
57 | if (arg_5) {
|
58 | options = arg_4;
|
59 | metadata = arg_5;
|
60 | } else {
|
61 | metadata = arg_4;
|
62 | }
|
63 |
|
64 | input = (0, _parse_["default"])(arg_1, {
|
65 | defaultCountry: arg_2,
|
66 | extended: true
|
67 | }, metadata);
|
68 | }
|
69 |
|
70 | else {
|
71 | if (typeof arg_2 !== 'string') {
|
72 | throw new Error('`format` argument not passed to `formatNumber(number, format)`');
|
73 | }
|
74 |
|
75 | format = arg_2;
|
76 |
|
77 | if (arg_4) {
|
78 | options = arg_3;
|
79 | metadata = arg_4;
|
80 | } else {
|
81 | metadata = arg_3;
|
82 | }
|
83 |
|
84 | input = (0, _parse_["default"])(arg_1, {
|
85 | extended: true
|
86 | }, metadata);
|
87 | }
|
88 | }
|
89 |
|
90 | else if (is_object(arg_1)) {
|
91 | input = arg_1;
|
92 | format = arg_2;
|
93 |
|
94 | if (arg_4) {
|
95 | options = arg_3;
|
96 | metadata = arg_4;
|
97 | } else {
|
98 | metadata = arg_3;
|
99 | }
|
100 | } else throw new TypeError('A phone number must either be a string or an object of shape { phone, [country] }.');
|
101 |
|
102 |
|
103 | if (format === 'International') {
|
104 | format = 'INTERNATIONAL';
|
105 | } else if (format === 'National') {
|
106 | format = 'NATIONAL';
|
107 | }
|
108 |
|
109 | return {
|
110 | input: input,
|
111 | format: format,
|
112 | options: options,
|
113 | metadata: metadata
|
114 | };
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | var is_object = function is_object(_) {
|
122 | return _typeof(_) === 'object';
|
123 | };
|
124 |
|
\ | No newline at end of file |