mirror of
https://github.com/Expand-sys/ccashfrontend
synced 2025-12-19 16:12:14 +11:00
124 lines
No EOL
4.2 KiB
JavaScript
124 lines
No EOL
4.2 KiB
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports["default"] = formatNumber;
|
|
|
|
var _format_ = _interopRequireDefault(require("./format_"));
|
|
|
|
var _parse_ = _interopRequireDefault(require("./parse_"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
|
|
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); }
|
|
|
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
|
|
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
|
|
|
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; }
|
|
|
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
|
function formatNumber() {
|
|
var _normalizeArguments = normalizeArguments(arguments),
|
|
input = _normalizeArguments.input,
|
|
format = _normalizeArguments.format,
|
|
options = _normalizeArguments.options,
|
|
metadata = _normalizeArguments.metadata;
|
|
|
|
return (0, _format_["default"])(input, format, options, metadata);
|
|
} // Sort out arguments
|
|
|
|
|
|
function normalizeArguments(args) {
|
|
var _Array$prototype$slic = Array.prototype.slice.call(args),
|
|
_Array$prototype$slic2 = _slicedToArray(_Array$prototype$slic, 5),
|
|
arg_1 = _Array$prototype$slic2[0],
|
|
arg_2 = _Array$prototype$slic2[1],
|
|
arg_3 = _Array$prototype$slic2[2],
|
|
arg_4 = _Array$prototype$slic2[3],
|
|
arg_5 = _Array$prototype$slic2[4];
|
|
|
|
var input;
|
|
var format;
|
|
var options;
|
|
var metadata; // Sort out arguments.
|
|
// If the phone number is passed as a string.
|
|
// `format('8005553535', ...)`.
|
|
|
|
if (typeof arg_1 === 'string') {
|
|
// If country code is supplied.
|
|
// `format('8005553535', 'RU', 'NATIONAL', [options], metadata)`.
|
|
if (typeof arg_3 === 'string') {
|
|
format = arg_3;
|
|
|
|
if (arg_5) {
|
|
options = arg_4;
|
|
metadata = arg_5;
|
|
} else {
|
|
metadata = arg_4;
|
|
}
|
|
|
|
input = (0, _parse_["default"])(arg_1, {
|
|
defaultCountry: arg_2,
|
|
extended: true
|
|
}, metadata);
|
|
} // Just an international phone number is supplied
|
|
// `format('+78005553535', 'NATIONAL', [options], metadata)`.
|
|
else {
|
|
if (typeof arg_2 !== 'string') {
|
|
throw new Error('`format` argument not passed to `formatNumber(number, format)`');
|
|
}
|
|
|
|
format = arg_2;
|
|
|
|
if (arg_4) {
|
|
options = arg_3;
|
|
metadata = arg_4;
|
|
} else {
|
|
metadata = arg_3;
|
|
}
|
|
|
|
input = (0, _parse_["default"])(arg_1, {
|
|
extended: true
|
|
}, metadata);
|
|
}
|
|
} // If the phone number is passed as a parsed number object.
|
|
// `format({ phone: '8005553535', country: 'RU' }, 'NATIONAL', [options], metadata)`.
|
|
else if (is_object(arg_1)) {
|
|
input = arg_1;
|
|
format = arg_2;
|
|
|
|
if (arg_4) {
|
|
options = arg_3;
|
|
metadata = arg_4;
|
|
} else {
|
|
metadata = arg_3;
|
|
}
|
|
} else throw new TypeError('A phone number must either be a string or an object of shape { phone, [country] }.'); // Legacy lowercase formats.
|
|
|
|
|
|
if (format === 'International') {
|
|
format = 'INTERNATIONAL';
|
|
} else if (format === 'National') {
|
|
format = 'NATIONAL';
|
|
}
|
|
|
|
return {
|
|
input: input,
|
|
format: format,
|
|
options: options,
|
|
metadata: metadata
|
|
};
|
|
} // Babel transforms `typeof` into some "branches"
|
|
// so istanbul will show this as "branch not covered".
|
|
|
|
/* istanbul ignore next */
|
|
|
|
|
|
var is_object = function is_object(_) {
|
|
return _typeof(_) === 'object';
|
|
};
|
|
//# sourceMappingURL=format.js.map
|